college-courses/app/Policies/CoursePolicy.php

33 lines
596 B
PHP
Raw Normal View History

2024-10-15 10:15:40 +03:00
<?php
namespace App\Policies;
use App\Models\Course;
use App\Models\User;
class CoursePolicy
{
/**
* Create a new policy instance.
*/
public function __construct()
{
//
}
public function create(User $user)
{
return !$user->isRole('student');
}
public function update(User $user, $course)
{
if (is_string($course)) {
$course_ = Course::where('slug', $course)->first();
} else {
$course_ = $course;
}
return $user->id === $course_->user_id || $user->isRole('admin');
}
}