37 lines
744 B
PHP
37 lines
744 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class StudentService implements ServiceInterface
|
|
{
|
|
public function getAll(): LengthAwarePaginator
|
|
{
|
|
return Student::filter()->paginate(10)->withQueryString();
|
|
}
|
|
|
|
public function create(array $data): User
|
|
{
|
|
$user = User::create($data['credentials']);
|
|
$student = Student::create($data['user_data']);
|
|
$student->user()->save($user);
|
|
|
|
return $student;
|
|
}
|
|
|
|
public function update($model, array $data): User
|
|
{
|
|
$model->update($data);
|
|
|
|
return $model;
|
|
}
|
|
|
|
public function delete($model): void
|
|
{
|
|
$model->destroy();
|
|
}
|
|
}
|