laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

Call to undefined method Illuminate\\Database\\Query\\Builder::detach()

Open djoks opened this issue 9 years ago • 0 comments
trafficstars

I am trying to remove all roles assigned to a user before deleting that user but this error keeps popping up. This is what I did:

public function destroy($id)
{
    try {
        // Finding user
        $user = User::find($id);

        // Finding profile
        $profile = Profile::where('user_id', $user->id)->first();

        // Revoking user's roles
        $user->revokeAllRoles();

        // Soft deleting user's profile
        $profile->delete();

        // Soft deleting user
        $user->delete();

        return response()->json([
            'messages' => ['User "' . $user->login_name . '" has been removed.']
        ], 200);

    }
    catch (\Exception $e) {
        return response()->json([
            'errors' => [$e->getMessage()]
        ], 500);
    }
}

I dunno what I am doing wrong here or how to fix it.

djoks avatar Jul 31 '16 22:07 djoks