From 282cb4be957b8d1c08dd616c344834827dee0812 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Thu, 26 Dec 2019 09:42:03 +0500 Subject: [PATCH] Check for no roles being attached #480 (#483) --- app/Http/Controllers/Admin/UserController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 55bef110..0f669212 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -243,9 +243,11 @@ class UserController extends Controller } // Delete all of the roles and then re-attach the valid ones - DB::table('role_user')->where('user_id', $id)->delete(); - foreach ($request->input('roles') as $key => $value) { - $user->attachRole($value); + if (!empty($request->input('roles'))) { + DB::table('role_user')->where('user_id', $id)->delete(); + foreach ($request->input('roles') as $key => $value) { + $user->attachRole($value); + } } Flash::success('User updated successfully.');