1 | <?php |
||
10 | class Permission extends Model implements AclPermissionInterface |
||
11 | { |
||
12 | use UserAndPermission; |
||
13 | |||
14 | /** |
||
15 | * The attributes that should be cast to native types. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $casts = ['id' => 'integer']; |
||
20 | |||
21 | /** |
||
22 | * The attributes that aren't mass assignable. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $guarded = ['id', 'created_id', 'updated_at']; |
||
27 | |||
28 | /** |
||
29 | * PERMISSION |
||
30 | * A Permission belongs to a level |
||
31 | * |
||
32 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
33 | */ |
||
34 | 10 | public function level() |
|
38 | |||
39 | /** |
||
40 | * PERMISSION |
||
41 | * A permission belongs to many users |
||
42 | * |
||
43 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
44 | */ |
||
45 | 8 | public function users() |
|
49 | |||
50 | /** |
||
51 | * PERMISSION |
||
52 | * Return the relationship of users |
||
53 | * |
||
54 | * @return mixed |
||
55 | */ |
||
56 | 1 | public function getUsers() |
|
60 | |||
61 | /** |
||
62 | * PERMISSION |
||
63 | * Assign a single user to a permission |
||
64 | * |
||
65 | * @param $user |
||
66 | */ |
||
67 | 3 | public function addUser($user) |
|
71 | |||
72 | /** |
||
73 | * PERMISSION |
||
74 | * Assign an array of users to a permission |
||
75 | * |
||
76 | * @param $users |
||
77 | */ |
||
78 | 6 | public function addUsers($users) |
|
84 | |||
85 | /** |
||
86 | * PERMISSION |
||
87 | * Remove a single user from a permission |
||
88 | * |
||
89 | * @param $user |
||
90 | */ |
||
91 | 1 | public function removeUser($user) |
|
95 | |||
96 | /** |
||
97 | * PERMISSION |
||
98 | * Remove an array of users from a permission |
||
99 | * |
||
100 | * @param $users |
||
101 | */ |
||
102 | 2 | public function removeUsers($users) |
|
108 | |||
109 | |||
110 | /* ------------------------------------------------------------------------------------------------ |
||
111 | | Other Functions |
||
112 | | ------------------------------------------------------------------------------------------------ |
||
113 | */ |
||
114 | |||
115 | /** |
||
116 | * Helper function to process users and return an |
||
117 | * array of user id's |
||
118 | * |
||
119 | * @param $users |
||
120 | * @return array |
||
121 | */ |
||
122 | 6 | protected function buildUserArray($users) |
|
133 | |||
134 | /** |
||
135 | * Handle model events |
||
136 | */ |
||
137 | 55 | public static function boot() |
|
146 | |||
147 | 55 | public function __construct(array $attributes = []) |
|
153 | } |
||
154 |