diff --git a/app/Http/Controllers/PenggunaController.php b/app/Http/Controllers/PenggunaController.php index fe55e4e1..7540a017 100644 --- a/app/Http/Controllers/PenggunaController.php +++ b/app/Http/Controllers/PenggunaController.php @@ -91,6 +91,22 @@ class PenggunaController extends Controller { return redirect()->route('pengguna.index')->with('failed','Maaf, Nama Pengguna / Emel Berikut Telah Wujud !'); } else { + + $allroles = Role::all()->pluck('name'); + $arraytaraf = []; + $counttaraf = 0; + foreach($allroles as $index=>$taraf) { + $req = 'taraf'.$taraf; + if($request->$req) + { + $counttaraf++; + array_push($arraytaraf,$taraf); + } + } + if($counttaraf < 1){ + return redirect()->route('pengguna.index')->with('failed','Maaf, Taraf Tidak Dipilih'); + } + $user = new User; $user->name = $request->name; $user->username = $request->username; @@ -103,18 +119,12 @@ class PenggunaController extends Controller $user->user_type = 1; $user->save(); - $allroles = Role::all()->pluck('name'); - $arraytaraf = []; - foreach($allroles as $index=>$taraf) { - $req = 'taraf'.$taraf; - if($request->$req) - { - array_push($arraytaraf,$taraf); - } - } $user->syncRoles($arraytaraf); - return redirect()->route('pengguna.index') - ->with('success', 'Pengguna Berjaya Disimpan'); + return redirect()->route('pengguna.index') + ->with('success', 'Pengguna Berjaya Disimpan'); + + + } }