|
|
|
@ -151,11 +151,17 @@ class UserController extends Controller {
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(User $user) {
|
|
|
|
|
//check if the current user is admin, then if there is only one admin - don't delete
|
|
|
|
|
|
|
|
|
|
$adminRole = Role::where('slug','admin')->first();
|
|
|
|
|
$userRoles = $user->roles;
|
|
|
|
|
|
|
|
|
|
if ($userRoles->contains($adminRole)) {
|
|
|
|
|
//the current user is admin, then if there is only one admin - don't delete
|
|
|
|
|
$numberOfAdmins = Role::where('slug', 'admin')->first()->users()->count();
|
|
|
|
|
if (1 == $numberOfAdmins) {
|
|
|
|
|
return response(['error' => 1, 'message' => 'Create another admin before deleting this only admin user'], 409);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user->delete();
|
|
|
|
|
|
|
|
|
|