2024-04-23 14:52:49 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Teacher;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
class TeacherService
|
2024-04-23 14:52:49 +04:00
|
|
|
{
|
2024-04-27 15:10:21 +04:00
|
|
|
public function create(array $data): Teacher
|
2024-04-23 14:52:49 +04:00
|
|
|
{
|
2024-04-27 15:10:21 +04:00
|
|
|
$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'],
|
|
|
|
]);
|
2024-04-23 14:52:49 +04:00
|
|
|
$teacher->user()->save($user);
|
|
|
|
|
|
|
|
return $teacher;
|
|
|
|
}
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
public function update(Teacher $teacher, array $data): Teacher
|
2024-04-23 14:52:49 +04:00
|
|
|
{
|
2024-06-16 12:20:48 +04:00
|
|
|
$teacher->user()->update([
|
2024-04-27 15:10:21 +04:00
|
|
|
'email' => $data['email'],
|
|
|
|
'password' => $data['password'],
|
|
|
|
]);
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
$teacher->update([
|
2024-04-27 15:10:21 +04:00
|
|
|
'name' => $data['name'],
|
|
|
|
'last_name' => $data['last_name'],
|
|
|
|
'middle_name' => $data['middle_name'],
|
|
|
|
'birthday' => $data['birthday'],
|
|
|
|
]);
|
2024-04-23 14:52:49 +04:00
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
return $teacher;
|
2024-04-23 14:52:49 +04:00
|
|
|
}
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
public function delete(Teacher $teacher): void
|
2024-04-23 14:52:49 +04:00
|
|
|
{
|
2024-06-16 12:20:48 +04:00
|
|
|
$teacher->user()->delete();
|
|
|
|
$teacher->delete();
|
2024-04-23 14:52:49 +04:00
|
|
|
}
|
|
|
|
}
|