| 1 |  |  | <?php namespace Arcanedev\LaravelAuth\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Arcanedev\LaravelAuth\Bases\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Arcanedev\LaravelAuth\Traits\Slugable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Arcanesoft\Contracts\Auth\Models\Permission as PermissionContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Arcanesoft\Contracts\Auth\Models\PermissionsGroup as PermissionsGroupContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Database\Eloquent\Model as Eloquent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class     PermissionsGroup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @package  Arcanedev\LaravelAuth\Models | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author   ARCANEDEV <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @property  int                                       id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @property  string                                    name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @property  string                                    slug | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @property  string                                    description | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @property  \Carbon\Carbon                            created_at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @property  \Carbon\Carbon                            updated_at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @property  \Illuminate\Database\Eloquent\Collection  permissions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class PermissionsGroup extends Model implements PermissionsGroupContract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      |  Traits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     use Slugable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      |  Properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * The attributes that are mass assignable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     protected $fillable = ['name', 'slug', 'description']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      |  Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * Create a new Eloquent model instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param  array  $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 528 |  |     public function __construct(array $attributes = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 528 |  |         $this->setTable(config('laravel-auth.permissions-groups.table', 'permissions_groups')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 528 |  |         parent::__construct($attributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 528 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      |  Relationships | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Permissions Groups has many permissions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\HasMany | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 104 |  |     public function permissions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 104 |  |         return $this->hasMany(config('laravel-auth.permissions.model', Permission::class), 'group_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      |  Getters & Setters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * Set the name attribute. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @param  string  $name | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 104 |  |     public function setNameAttribute($name) | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 104 |  |         $this->attributes['name'] = $name; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 104 |  |         $this->setSlugAttribute($name); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 | 104 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * Set the slug attribute. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param  string  $slug | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 104 |  |     public function setSlugAttribute($slug) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 104 |  |         $this->attributes['slug'] = $this->slugify($slug); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 104 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      |  CRUD Functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * Create and attach a permission. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * @param  array  $attributes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param  bool   $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 16 |  |     public function createPermission(array $attributes, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 16 |  |         $this->permissions()->create($attributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 16 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 16 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * Attach the permission to a group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * @param  \Arcanesoft\Contracts\Auth\Models\Permission  $permission | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param  bool                                          $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 48 |  |     public function attachPermission(&$permission, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 48 |  |         if ($this->hasPermission($permission)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 8 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 48 |  |         $permission = $this->permissions()->save($permission); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 48 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 48 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * Attach the permission by id to a group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * @param  int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param  bool  $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @return \Arcanesoft\Contracts\Auth\Models\Permission | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 8 |  |     public function attachPermissionById($id, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 8 |  |         $permission = $this->getPermissionById($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 8 |  |         if ( ! is_null($permission)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 8 |  |             $this->attachPermission($permission, $reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 6 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 8 |  |         return $permission; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * Attach a collection of permissions to the group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @param  \Illuminate\Database\Eloquent\Collection|array  $permissions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * @param  bool                                            $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * @return \Illuminate\Database\Eloquent\Collection|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 24 |  |     public function attachPermissions($permissions, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 24 |  |         $permissions = $this->permissions()->saveMany($permissions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 24 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 | 24 |  |         return $permissions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * Attach the permission from a group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @param  \Arcanesoft\Contracts\Auth\Models\Permission  $permission | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * @param  bool                                          $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 24 |  |     public function detachPermission(&$permission, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 24 |  |         if ( ! $this->hasPermission($permission)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 16 |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 24 |  |         $permission = $this->getPermissionFromGroup($permission); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 24 |  |         $permission->update([ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 24 |  |             'group_id' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 18 |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 24 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 24 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * Attach the permission by id to a group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @param  int   $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * @param  bool  $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * @return \Arcanesoft\Contracts\Auth\Models\Permission | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 8 |  |     public function detachPermissionById($id, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 8 |  |         $permission = $this->getPermissionById($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 | 8 |  |         if ( ! is_null($permission)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 | 8 |  |             $this->detachPermission($permission, $reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 6 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 8 |  |         return $permission; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * Detach multiple permissions by ids. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @param  array  $ids | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * @param  bool   $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 | 8 |  |     public function detachPermissions(array $ids, $reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 | 8 |  |         $detached = $this->permissions()->whereIn('id', $ids)->update([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |             'group_id' => 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 8 |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 8 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 8 |  |         return $detached; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |      * Detach all permissions from the group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * @param  bool  $reload | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 | 16 |  |     public function detachAllPermissions($reload = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 | 16 |  |         $detached = $this->permissions()->update([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             'group_id' => 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 | 16 |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 16 |  |         $this->loadPermissions($reload); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 | 16 |  |         return $detached; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      |  Check Functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      * Check if role has the given permission (Permission Model or Id). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |      * @param  \Arcanesoft\Contracts\Auth\Models\Permission|int  $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 | 64 |  |     public function hasPermission($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 | 64 |  |         if ($id instanceof Eloquent) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 64 |  |             $id = $id->getKey(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 | 48 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 | 64 |  |         return ! is_null($this->getPermissionFromGroup($id)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      |  Other Functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |      * Get a permission from the group. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |      * @param  \Arcanesoft\Contracts\Auth\Models\Permission|int  $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |      * @return \Arcanesoft\Contracts\Auth\Models\Permission|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 64 |  |     private function getPermissionFromGroup($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 64 |  |         if ($id instanceof Eloquent) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 | 24 |  |             $id = $id->getKey(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 | 18 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 64 |  |         $this->loadPermissions(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 64 |  |         return $this->permissions->filter(function (PermissionContract $permission) use ($id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 | 64 |  |             return $permission->id == $id; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 | 64 |  |         })->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * Get a permission by id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |      * @param  int  $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |      * @return \Arcanesoft\Contracts\Auth\Models\Permission|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 | 16 |  |     private function getPermissionById($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 | 16 |  |         return $this->permissions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 | 16 |  |             ->getRelated() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 | 16 |  |             ->where('id', $id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 | 16 |  |             ->first(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * Load the permissions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |      * @param  bool  $load | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |      * @return self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 | 88 |  |     protected function loadPermissions($load = true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 | 88 |  |         return $load ? $this->load('permissions') : $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 313 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 314 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.