laravel-acl
laravel-acl copied to clipboard
Call to undefined method Illuminate\\Database\\Query\\Builder::detach()
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.