app/Api/V1/Controllers/UserController.php
/**
     * protected function to handle syncing permissions
     * @param Request $request
     * @param $user
     * @return
     */
protected function to handle syncing permissions
@param Request $request
@param $user
@return
protected function to handle syncing permissions @param Request $request @param $user @return
protected function syncPermissions(Request $request, $user)
    {
        $roles = $request->get('roles', []);
        $permissions = $request->get('permissions', []);
        $roles = Role::find($roles);
        if (!$user->hasAllRoles($roles)) {
            $user->permissions()->sync([]);
        } else {
            $user->syncPermissions($permissions);
        }
        $user->syncRoles($roles);
        return $user;
    }
protected function syncPermissions ( Request $ request , $ user ) { $ roles = $ request -> get ( 'roles' , [ ] ) ; $ permissions = $ request -> get ( 'permissions' , [ ] ) ; $ roles = Role :: find ( $ roles ) ; if ( ! $ user -> hasAllRoles ( $ roles ) ) { $ user -> permissions ( ) -> sync ( [ ] ) ; } else { $ user -> syncPermissions ( $ permissions ) ; } $ user -> syncRoles ( $ roles ) ; return $ user ; }
protected function to handle syncing permissions
 @param Request $request
 @param $user
 @return
protected function to handle syncing permissions @param Request $request @param $user @return
// Get the submitted roles // Get the roles // check for current role changes // reset all direct permissions for user // handle permissions