CourseWork/app/Services/TeacherService.php
2024-06-16 12:20:48 +04:00

51 lines
1.2 KiB
PHP

<?php
namespace App\Services;
use App\Models\Teacher;
use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator;
class TeacherService
{
public function create(array $data): Teacher
{
$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(Teacher $teacher, array $data): Teacher
{
$teacher->user()->update([
'email' => $data['email'],
'password' => $data['password'],
]);
$teacher->update([
'name' => $data['name'],
'last_name' => $data['last_name'],
'middle_name' => $data['middle_name'],
'birthday' => $data['birthday'],
]);
return $teacher;
}
public function delete(Teacher $teacher): void
{
$teacher->user()->delete();
$teacher->delete();
}
}