CourseWork/app/Services/StudentService.php

37 lines
744 B
PHP
Raw Normal View History

2024-04-23 14:52:49 +04:00
<?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();
}
}