public function setPermissionsAttribute(array $permissions)
    {
        if (!$this->id) {
            $this->save();
        }

        $this->revokeAll();

        collect($permissions)->map(function ($permission) {
            if (!in_array($permission, Policy::all())) {
                return;
            }

            $this->grant($permission);
        });
    }
public function setPermissionsAttribute(array $permissions)
    {
        if (!$this->id) {
            $this->save();
        }

        $this->revokeAll();

        collect($permissions)->map(function ($permission) {
            if (!in_array($permission, Policy::all())) {
                return;
            }

            $this->grant($permission);
        });
    }
public function setPermissionsAttribute ( array $ permissions ) { if ( ! $ this -> id ) { $ this -> save ( ) ; } $ this -> revokeAll ( ) ; collect ( $ permissions ) -> map ( function ( $ permission ) { if ( ! in_array ( $ permission , Policy :: all ( ) ) ) { return ; } $ this -> grant ( $ permission ) ; } ) ; }
Replace all existing permissions with a new set of permissions

@param array $permissions
@return void
Replace all existing permissions with a new set of permissions