@Tray2 In your example you are missing the 'owner_id'. I would do something like:
public function destroy(User $user)
{
// validate if the user we want to delete is owned by the currently logged in user
// note: you could also move this permission logic to "Policies"
if ($user->owner_id !== Auth::id()) {
abort(403); // throws an "Unauthorized" exception
}
// delete the user passed in the url
$user->delete();
// redirect back to the user index
return redirect('/users');
}
@behnampmdg3 not "wrong" but it could be easier like in my example above. Why a custom query builder when you already have the user object and you just use the delete() method, easier to code, easier to read.