33 lines
596 B
PHP
33 lines
596 B
PHP
|
<?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');
|
||
|
}
|
||
|
}
|