app/Http/Controllers/Admin/UsersController.php
// Remove User from DB with detaching Role
Remove User from DB with detaching Role
Remove User from DB with detaching Role
public function destroy($id)
    {
        if (Auth::user()->ability('superadministrator','delete-users')) {
            try {
                $user = User::findOrFail($id);
                $roles = $user->roles;
                foreach ($roles as $key => $value) {
                    $user->detachRole($value);
                }
                $user->delete();
                return redirect()->route('users.index')->withSuccess('success', "The user $user->name has successfully been archived.");
            } catch (ModelNotFoundException $ex) {
                if ($ex instanceof ModelNotFoundException) {
                    return response()->view('errors.' . '404');
                }
            }
        }
        return abort(403,'No such permission, please contact the administrator!');
    }
public function destroy ( $ id ) { if ( Auth :: user ( ) -> ability ( 'superadministrator' , 'delete-users' ) ) { try { $ user = User :: findOrFail ( $ id ) ; $ roles = $ user -> roles ; foreach ( $ roles as $ key => $ value ) { $ user -> detachRole ( $ value ) ; } $ user -> delete ( ) ; return redirect ( ) -> route ( 'users.index' ) -> withSuccess ( 'success' , " The user  $ user -> name  has successfully been archived. " ) ; } catch ( ModelNotFoundException $ ex ) { if ( $ ex instanceof ModelNotFoundException ) { return response ( ) -> view ( 'errors.' . '404' ) ; } } } return abort ( 403 , 'No such permission, please contact the administrator!' ) ; }
Remove User from DB with detaching Role
Remove User from DB with detaching Role
// Detach from Role