37 lines
744 B
PHP
37 lines
744 B
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(10)->withQueryString();
|
||
|
}
|
||
|
|
||
|
public function create(array $data): User
|
||
|
{
|
||
|
$user = User::create($data['credentials']);
|
||
|
$teacher = Teacher::create($data['user_data']);
|
||
|
$teacher->user()->save($user);
|
||
|
|
||
|
return $teacher;
|
||
|
}
|
||
|
|
||
|
public function update($model, array $data): User
|
||
|
{
|
||
|
$model->update($data);
|
||
|
|
||
|
return $model;
|
||
|
}
|
||
|
|
||
|
public function delete($model): void
|
||
|
{
|
||
|
$model->destroy();
|
||
|
}
|
||
|
}
|