1 | <?php |
||
14 | class Permission extends Model implements AclPermissionInterface |
||
15 | { |
||
16 | use UserAndPermission; |
||
17 | |||
18 | /** |
||
19 | * The attributes that should be cast to native types. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $casts = ['id' => 'integer']; |
||
24 | |||
25 | /** |
||
26 | * The attributes that aren't mass assignable. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $guarded = ['id', 'created_id', 'updated_at']; |
||
31 | |||
32 | /** |
||
33 | * PERMISSION |
||
34 | * A Permission belongs to a level |
||
35 | * |
||
36 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
37 | */ |
||
38 | 10 | public function level() |
|
42 | |||
43 | /** |
||
44 | * PERMISSION |
||
45 | * A permission belongs to many users |
||
46 | * |
||
47 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
48 | */ |
||
49 | 8 | public function users() |
|
53 | |||
54 | /** |
||
55 | * PERMISSION |
||
56 | * Return the relationship of users |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | 1 | public function getUsers() |
|
64 | |||
65 | /** |
||
66 | * PERMISSION |
||
67 | * Assign a single user to a permission |
||
68 | * |
||
69 | * @param $user |
||
70 | */ |
||
71 | 3 | public function addUser($user) |
|
75 | |||
76 | /** |
||
77 | * PERMISSION |
||
78 | * Assign an array of users to a permission |
||
79 | * |
||
80 | * @param $users |
||
81 | */ |
||
82 | 6 | public function addUsers($users) |
|
88 | |||
89 | /** |
||
90 | * PERMISSION |
||
91 | * Remove a single user from a permission |
||
92 | * |
||
93 | * @param $user |
||
94 | */ |
||
95 | 1 | public function removeUser($user) |
|
99 | |||
100 | /** |
||
101 | * PERMISSION |
||
102 | * Remove an array of users from a permission |
||
103 | * |
||
104 | * @param $users |
||
105 | */ |
||
106 | 2 | public function removeUsers($users) |
|
112 | |||
113 | |||
114 | /* ------------------------------------------------------------------------------------------------ |
||
115 | | Other Functions |
||
116 | | ------------------------------------------------------------------------------------------------ |
||
117 | */ |
||
118 | |||
119 | /** |
||
120 | * Helper function to process users and return an |
||
121 | * array of user id's |
||
122 | * |
||
123 | * @param $users |
||
124 | * @return array |
||
125 | */ |
||
126 | 6 | protected function buildUserArray($users) |
|
137 | |||
138 | /** |
||
139 | * Handle model events |
||
140 | */ |
||
141 | 55 | public static function boot() |
|
150 | |||
151 | 55 | public function __construct(array $attributes = []) |
|
157 | } |
||
158 |