prod #7
@ -29,7 +29,7 @@ class StudentPostRequest extends FormRequest
|
||||
'middle_name' => 'required|max:255',
|
||||
'birthday' => 'required|date',
|
||||
'grade_id' => 'required|exists:grades,id',
|
||||
'login' => 'required|max:255|lowercase|unique:users,login',
|
||||
'email' => 'required|max:255|lowercase|unique:users,email',
|
||||
'password' => 'required|max:255',
|
||||
];
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class TeacherPostRequest extends FormRequest
|
||||
'last_name' => 'required|max:255',
|
||||
'middle_name' => 'required|max:255',
|
||||
'birthday' => 'required|date',
|
||||
'login' => 'required|max:255|lowercase|unique:users,login',
|
||||
'email' => 'required|max:255|lowercase|unique:users,email',
|
||||
'password' => 'required|max:255',
|
||||
];
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@ -16,6 +17,7 @@ class Student extends Model
|
||||
'last_name',
|
||||
'middle_name',
|
||||
'birthday',
|
||||
'grade_id',
|
||||
];
|
||||
|
||||
public function grade(): BelongsTo
|
||||
@ -40,4 +42,11 @@ class Student extends Model
|
||||
$query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]);
|
||||
});
|
||||
}
|
||||
|
||||
public function fio(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->last_name . " " . $this->name . " " . $this->middle_name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
@ -45,4 +46,11 @@ class Teacher extends Model
|
||||
$query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]);
|
||||
});
|
||||
}
|
||||
|
||||
public function fio(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->last_name . " " . $this->name . " " . $this->middle_name,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Student;
|
||||
use App\Models\Teacher;
|
||||
use App\Models\User;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
@ -13,24 +14,45 @@ class StudentService implements ServiceInterface
|
||||
return Student::filter()->paginate(10)->withQueryString();
|
||||
}
|
||||
|
||||
public function create(array $data): User
|
||||
public function create(array $data): Student
|
||||
{
|
||||
$user = User::create($data['credentials']);
|
||||
$student = Student::create($data['user_data']);
|
||||
$user = User::create([
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]);
|
||||
$student = Student::create([
|
||||
'name' => $data['name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'middle_name' => $data['middle_name'],
|
||||
'birthday' => $data['birthday'],
|
||||
'grade_id' => $data['grade_id'],
|
||||
]);
|
||||
$student->user()->save($user);
|
||||
|
||||
return $student;
|
||||
}
|
||||
|
||||
public function update($model, array $data): User
|
||||
public function update($model, array $data): Student
|
||||
{
|
||||
$model->update($data);
|
||||
$model->user()->update([
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]);
|
||||
|
||||
$model->update([
|
||||
'name' => $data['name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'middle_name' => $data['middle_name'],
|
||||
'birthday' => $data['birthday'],
|
||||
'grade_id' => $data['grade_id'],
|
||||
]);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function delete($model): void
|
||||
{
|
||||
$model->destroy();
|
||||
$model->user()->delete();
|
||||
$model->delete();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Student;
|
||||
use App\Models\Teacher;
|
||||
use App\Models\User;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
@ -13,24 +14,43 @@ class TeacherService implements ServiceInterface
|
||||
return Teacher::filter()->paginate(10)->withQueryString();
|
||||
}
|
||||
|
||||
public function create(array $data): User
|
||||
public function create(array $data): Teacher
|
||||
{
|
||||
$user = User::create($data['credentials']);
|
||||
$teacher = Teacher::create($data['user_data']);
|
||||
$user = User::create([
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]);
|
||||
$teacher = Teacher::create([
|
||||
'name' => $data['name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'middle_name' => $data['middle_name'],
|
||||
'birthday' => $data['birthday'],
|
||||
]);
|
||||
$teacher->user()->save($user);
|
||||
|
||||
return $teacher;
|
||||
}
|
||||
|
||||
public function update($model, array $data): User
|
||||
public function update($model, array $data): Teacher
|
||||
{
|
||||
$model->update($data);
|
||||
$model->user()->update([
|
||||
'email' => $data['email'],
|
||||
'password' => $data['password'],
|
||||
]);
|
||||
|
||||
$model->update([
|
||||
'name' => $data['name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'middle_name' => $data['middle_name'],
|
||||
'birthday' => $data['birthday'],
|
||||
]);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function delete($model): void
|
||||
{
|
||||
$model->destroy();
|
||||
$model->user()->delete();
|
||||
$model->delete();
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ return new class extends Migration
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->morphs('userable');
|
||||
$table->nullableMorphs('userable');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
@ -32,6 +32,14 @@
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Эл. почта:</label>
|
||||
<input type="text" id="email" name="email" class="form-control" value="{{ isset($student) ? $student->email : old('email') }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Пароль:</label>
|
||||
<input type="text" id="password" name="password" class="form-control" value="{{ isset($student) ? $student->password : old('password') }}" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Подтвердить</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -7,17 +7,17 @@
|
||||
<div class="card-header">{{ ('Ученик') }}</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<h5><strong>ФИО: </strong>{{ $user->last_name }} {{ $user->name }} {{ $user->middle_name }}</h5>
|
||||
<h5><strong>ФИО: </strong>{{ $student->fio }}</h5>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<h5><strong>Класс: </strong>{{ $user->class->name }}</h5>
|
||||
<h5><strong>Класс: </strong>{{ $student->grade->name }}</h5>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<h5><strong>Дата рождения: </strong>{{ $user->birthday }}</h5>
|
||||
<h5><strong>Дата рождения: </strong>{{ $student->birthday }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a href="{{ route('users.edit', $user) }}" class="btn btn-primary">Редактировать</a>
|
||||
<a href="{{ route('students.edit', $student) }}" class="btn btn-primary">Редактировать</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -22,12 +22,12 @@
|
||||
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="birthday" class="form-label">Логин:</label>
|
||||
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
|
||||
<label for="email" class="form-label">Эл. почта:</label>
|
||||
<input type="text" id="email" name="email" class="form-control" value="{{ isset($teacher) ? $teacher->email : old('email') }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="birthday" class="form-label">Пароль:</label>
|
||||
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
|
||||
<label for="password" class="form-label">Пароль:</label>
|
||||
<input type="text" id="password" name="password" class="form-control" value="{{ isset($teacher) ? $teacher->password : old('password') }}" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Подтвердить</button>
|
||||
</form>
|
||||
|
@ -7,14 +7,14 @@
|
||||
<div class="card-header">{{ ('Учитель') }}</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<h5><strong>ФИО: </strong>{{ $user->last_name }} {{ $user->name }} {{ $user->middle_name }}</h5>
|
||||
<h5><strong>ФИО: </strong>{{ $teacher->fio }}</h5>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<h5><strong>Дата рождения: </strong>{{ $user->birthday }}</h5>
|
||||
<h5><strong>Дата рождения: </strong>{{ $teacher->birthday }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<a href="{{ route('users.edit', $user) }}" class="btn btn-primary">Редактировать</a>
|
||||
<a href="{{ route('teachers.edit', $teacher) }}" class="btn btn-primary">Редактировать</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user