56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Teacher;
|
|
use App\Models\User;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class TeacherService implements ServiceInterface
|
|
{
|
|
public function getAll(): LengthAwarePaginator
|
|
{
|
|
return Teacher::filter()->paginate(5)->withQueryString();
|
|
}
|
|
|
|
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($model, array $data): Teacher
|
|
{
|
|
$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->user()->delete();
|
|
$model->delete();
|
|
}
|
|
}
|