1 | <?php |
||
9 | class Permission extends Model |
||
10 | { |
||
11 | use UserAndPermission; |
||
12 | |||
13 | protected $guarded = ['id', 'created_id', 'updated_at']; |
||
14 | protected $casts = ['id' => 'integer']; |
||
15 | |||
16 | /** |
||
17 | * PERMISSION |
||
18 | * A Permission belongs to a level |
||
19 | * |
||
20 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
21 | */ |
||
22 | 9 | public function level() |
|
26 | |||
27 | /** |
||
28 | * PERMISSION |
||
29 | * A permission belongs to many users |
||
30 | * |
||
31 | * @return mixed |
||
32 | */ |
||
33 | 7 | public function users() |
|
37 | |||
38 | /** |
||
39 | * PERMISSION |
||
40 | * Assign a single user to a permission |
||
41 | * |
||
42 | * @param $user |
||
43 | */ |
||
44 | 3 | public function addUser($user) |
|
48 | |||
49 | /** |
||
50 | * PERMISSION |
||
51 | * Assign an array of users to a permission |
||
52 | * |
||
53 | * @param $users |
||
54 | */ |
||
55 | 5 | public function addUsers($users) |
|
61 | |||
62 | /** |
||
63 | * PERMISSION |
||
64 | * Remove a single user from a permission |
||
65 | * |
||
66 | * @param $user |
||
67 | */ |
||
68 | 1 | public function removeUser($user) |
|
72 | |||
73 | /** |
||
74 | * PERMISSION |
||
75 | * Remove an array of users from a permission |
||
76 | * |
||
77 | * @param $users |
||
78 | */ |
||
79 | 2 | public function removeUsers($users) |
|
85 | |||
86 | |||
87 | /* ------------------------------------------------------------------------------------------------ |
||
88 | | Other Functions |
||
89 | | ------------------------------------------------------------------------------------------------ |
||
90 | */ |
||
91 | /** |
||
92 | * PERMISSION |
||
93 | * Helper function to get the user whether it is the user ID |
||
94 | * or the user object itself. |
||
95 | * |
||
96 | * @param $user |
||
97 | * @return User |
||
98 | * @throws UserNotFoundException |
||
99 | */ |
||
100 | 5 | protected function getUser($user) |
|
110 | |||
111 | /** |
||
112 | * Helper function to process users and return an |
||
113 | * array of user id's |
||
114 | * |
||
115 | * @param $users |
||
116 | * @return array |
||
117 | */ |
||
118 | 5 | protected function buildUserArray($users) |
|
129 | |||
130 | /** |
||
131 | * Handle model events |
||
132 | */ |
||
133 | 48 | public static function boot() |
|
142 | } |
||
143 |