1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\Applicant; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use App\Models\Course; |
8
|
|
|
use App\Policies\BasePolicy; |
9
|
|
|
|
10
|
|
|
class CoursePolicy extends BasePolicy |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Determine whether the user can view the course. |
15
|
|
|
* |
16
|
|
|
* @param \App\Models\User $user |
17
|
|
|
* @param \App\Models\Course $course |
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
|
public function view(User $user, Course $course) |
21
|
|
|
{ |
22
|
|
|
return $user->isApplicant() |
23
|
|
|
&& $course->courseable instanceof Applicant |
24
|
|
|
&& $course->courseable->user->id === $user->id; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Determine whether the user can create courses. |
29
|
|
|
* |
30
|
|
|
* @param \App\Models\User $user |
31
|
|
|
* @return mixed |
32
|
|
|
*/ |
33
|
|
|
public function create(User $user) |
34
|
|
|
{ |
35
|
|
|
return $user->isApplicant(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine whether the user can update the course. |
40
|
|
|
* |
41
|
|
|
* @param \App\Models\User $user |
42
|
|
|
* @param \App\Models\Course $course |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function update(User $user, Course $course) |
46
|
|
|
{ |
47
|
|
|
return $user->isApplicant() |
48
|
|
|
&& $course->courseable instanceof Applicant |
49
|
|
|
&& $course->courseable->user->id === $user->id; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Determine whether the user can delete the course. |
54
|
|
|
* |
55
|
|
|
* @param \App\Models\User $user |
56
|
|
|
* @param \App\Models\Course $course |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public function delete(User $user, Course $course) |
60
|
|
|
{ |
61
|
|
|
return $user->isApplicant() |
62
|
|
|
&& $course->courseable instanceof Applicant |
63
|
|
|
&& $course->courseable->user->id === $user->id; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|