53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Policies;
|
||
|
|
||
|
use App\Models\Admin;
|
||
|
use App\Models\Grade;
|
||
|
use App\Models\Lesson;
|
||
|
use App\Models\Student;
|
||
|
use App\Models\User;
|
||
|
|
||
|
class LessonPolicy
|
||
|
{
|
||
|
/**
|
||
|
* Determine whether the user can view any models.
|
||
|
*/
|
||
|
public function viewAny(User $user, Grade $grade): bool
|
||
|
{
|
||
|
return $user->userable_type != Student::class || $user->userable->grade_id == $grade->id;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can view the model.
|
||
|
*/
|
||
|
public function view(User $user, Lesson $lesson): bool
|
||
|
{
|
||
|
return $user->userable_type != Student::class || $user->userable->grade_id == $lesson->grade_id;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can create models.
|
||
|
*/
|
||
|
public function create(User $user): bool
|
||
|
{
|
||
|
return $user->userable_type == Admin::class;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can update the model.
|
||
|
*/
|
||
|
public function update(User $user, Lesson $lesson): bool
|
||
|
{
|
||
|
return $user->userable_type == Admin::class;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine whether the user can delete the model.
|
||
|
*/
|
||
|
public function delete(User $user, Lesson $lesson): bool
|
||
|
{
|
||
|
return $user->userable_type == Admin::class;
|
||
|
}
|
||
|
}
|