1 | <?php |
||
15 | class Permission extends Model |
||
16 | { |
||
17 | use UserAndPermission; |
||
18 | |||
19 | protected $guarded = ['id', 'created_id', 'updated_at']; |
||
20 | protected $casts = ['id' => 'integer']; |
||
21 | |||
22 | /** |
||
23 | * PERMISSION |
||
24 | * A Permission belongs to a level |
||
25 | * |
||
26 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
27 | */ |
||
28 | public function level() |
||
32 | |||
33 | /** |
||
34 | * PERMISSION |
||
35 | * A permission belongs to many users |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public function users() |
||
43 | |||
44 | /** |
||
45 | * PERMISSION |
||
46 | * Assign a single user to a permission |
||
47 | * |
||
48 | * @param $user |
||
49 | */ |
||
50 | public function addUser($user) |
||
54 | |||
55 | /** |
||
56 | * PERMISSION |
||
57 | * Assign an array of users to a permission |
||
58 | * |
||
59 | * @param $users |
||
60 | */ |
||
61 | public function addUsers($users) |
||
67 | |||
68 | /** |
||
69 | * PERMISSION |
||
70 | * Remove a single user from a permission |
||
71 | * |
||
72 | * @param $user |
||
73 | */ |
||
74 | public function removeUser($user) |
||
78 | |||
79 | /** |
||
80 | * PERMISSION |
||
81 | * Remove an array of users from a permission |
||
82 | * |
||
83 | * @param $users |
||
84 | */ |
||
85 | public function removeUsers($users) |
||
91 | |||
92 | |||
93 | /* ------------------------------------------------------------------------------------------------ |
||
94 | | Other Functions |
||
95 | | ------------------------------------------------------------------------------------------------ |
||
96 | */ |
||
97 | /** |
||
98 | * PERMISSION |
||
99 | * Helper function to get the user whether it is the user ID |
||
100 | * or the user object itself. |
||
101 | * |
||
102 | * @param $user |
||
103 | * @return User |
||
104 | * @throws UserNotFoundException |
||
105 | */ |
||
106 | protected function getUser($user) |
||
116 | |||
117 | /** |
||
118 | * Helper function to process users and return an |
||
119 | * array of user id's |
||
120 | * |
||
121 | * @param $users |
||
122 | * @return array |
||
123 | */ |
||
124 | protected function buildUserArray($users) |
||
135 | |||
136 | /** |
||
137 | * Handle model events |
||
138 | */ |
||
139 | public static function boot() |
||
148 | } |
||
149 |