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 | protected $table; |
||
16 | |||
17 | /** |
||
18 | * PERMISSION |
||
19 | * A Permission belongs to a level |
||
20 | * |
||
21 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
22 | */ |
||
23 | 10 | public function level() |
|
27 | |||
28 | /** |
||
29 | * PERMISSION |
||
30 | * A permission belongs to many users |
||
31 | * |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 8 | public function users() |
|
38 | |||
39 | /** |
||
40 | * PERMISSION |
||
41 | * Return the relationship of users |
||
42 | * |
||
43 | * @return mixed |
||
44 | */ |
||
45 | 1 | public function getUsers() |
|
49 | |||
50 | /** |
||
51 | * PERMISSION |
||
52 | * Assign a single user to a permission |
||
53 | * |
||
54 | * @param $user |
||
55 | */ |
||
56 | 3 | public function addUser($user) |
|
60 | |||
61 | /** |
||
62 | * PERMISSION |
||
63 | * Assign an array of users to a permission |
||
64 | * |
||
65 | * @param $users |
||
66 | */ |
||
67 | 6 | public function addUsers($users) |
|
73 | |||
74 | /** |
||
75 | * PERMISSION |
||
76 | * Remove a single user from a permission |
||
77 | * |
||
78 | * @param $user |
||
79 | */ |
||
80 | 1 | public function removeUser($user) |
|
84 | |||
85 | /** |
||
86 | * PERMISSION |
||
87 | * Remove an array of users from a permission |
||
88 | * |
||
89 | * @param $users |
||
90 | */ |
||
91 | 2 | public function removeUsers($users) |
|
97 | |||
98 | |||
99 | /* ------------------------------------------------------------------------------------------------ |
||
100 | | Other Functions |
||
101 | | ------------------------------------------------------------------------------------------------ |
||
102 | */ |
||
103 | /** |
||
104 | * PERMISSION |
||
105 | * Helper function to get the user whether it is the user ID |
||
106 | * or the user object itself. |
||
107 | * |
||
108 | * @param $user |
||
109 | * @return User |
||
110 | * @throws UserNotFoundException |
||
111 | */ |
||
112 | 6 | protected function getUser($user) |
|
122 | |||
123 | /** |
||
124 | * Helper function to process users and return an |
||
125 | * array of user id's |
||
126 | * |
||
127 | * @param $users |
||
128 | * @return array |
||
129 | */ |
||
130 | 6 | protected function buildUserArray($users) |
|
141 | |||
142 | /** |
||
143 | * Handle model events |
||
144 | */ |
||
145 | 53 | public static function boot() |
|
154 | |||
155 | 53 | public function __construct(array $attributes = []) |
|
161 | } |
||
162 |