fix seeder, add user roles during register

This commit is contained in:
Amir
2022-07-28 12:55:19 +08:00
parent 39ea2d83ca
commit c10d435e86
5 changed files with 129 additions and 149 deletions
+13 -3
View File
@@ -35,12 +35,13 @@ class PenggunaController extends Controller
// $alluser = User::all();
$alluser = User::with('roles')->orderBy('id')->get();
$allroles = Role::all();
$allRolesPluck= $allroles->pluck('name');
$caw = Cawangan::all();
$user = User::with('roles')->first();
$userroles = $user->getRoleNames()->toArray();
// $user = Auth::user();
// $user->assignRole('admin');
return view('pengurusanpengguna.index',compact('alluser','allroles','caw','user','userroles'));
return view('pengurusanpengguna.index',compact('alluser','allroles','caw','user','userroles', 'allRolesPluck'));
}
@@ -87,9 +88,18 @@ class PenggunaController extends Controller
$user->email_verified_at = $currentdate;
$user->password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; //password
$user->user_type = 1;
// $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');
}
@@ -112,7 +122,7 @@ class PenggunaController extends Controller
array_push($arraytaraf,$taraf);
}
}
//dd($arraytaraf);
// dd($arraytaraf);
$user->syncRoles($arraytaraf);
if($request->status == true)