Merge branch 'nisha' into 'main'

pengurusan pengguna

See merge request online-sistem1/lelong!280
This commit is contained in:
Nur Izzati Zulkifli
2022-11-22 04:27:24 +00:00
2 changed files with 42 additions and 31 deletions
+39 -28
View File
@@ -72,40 +72,51 @@ class PenggunaController extends Controller
'username' => 'required|string|unique:users'
]);
if ($validator->fails()) {
$errors = [
'success' => "error",
'message' => $validator->errors()
// if ($validator->fails()) {
// $errors = [
// 'success' => "error",
// 'message' => $validator->errors()
];
// ];
return redirect()->route('pengguna.index')
->with('message', 'Sila Masukkan Email Yang Sah'); }
// return redirect()->route('pengguna.index')
// ->with('message', 'Sila Masukkan Email Yang Sah'); }
$user = new User;
$user->name = $request->name;
$user->username = $request->username;
$user->kodcaw = $request->caw;
$user->status = 'active';
$user->t_daftar = $currentdate;
$user->email = $request->email;
$user->email_verified_at = $currentdate;
$user->password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; //password
$user->user_type = 1;
$user->save();
//check if user already existed
$check = User::where('username',$request->username)
->orWhere('email',$request->email)
->first();
$allroles = Role::all()->pluck('name');
$arraytaraf = [];
foreach($allroles as $index=>$taraf) {
$req = 'taraf'.$taraf;
if($request->$req)
if($check)
{
array_push($arraytaraf,$taraf);
return redirect()->route('pengguna.index')->with('failed','Maaf, Nama Pengguna / Emel Berikut Telah Wujud !');
} else {
$user = new User;
$user->name = $request->name;
$user->username = $request->username;
$user->kodcaw = $request->caw;
$user->status = 'active';
$user->t_daftar = $currentdate;
$user->email = $request->email;
$user->email_verified_at = $currentdate;
$user->password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; //password
$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');
}
}
$user->syncRoles($arraytaraf);
return redirect()->route('pengguna.index')
->with('success', 'Pengguna Berjaya Disimpan');
}
public function store(Request $request)
+3 -3
View File
@@ -43,16 +43,16 @@
</div>
<div class="custom-control custom-switch" >
<input type="checkbox" class="custom-control-input" name="status" id="customSwitch1" onchange="showstatus(this)">
<label class="custom-control-label" for="customSwitch1" data-status="{{ $user->status }}" id="txtstatus"></lable>
<label class="custom-control-label" for="customSwitch1" data-status="{{ $user->status }}" id="txtstatus"></label>
</div>
</div>
<div class="d-flex col-md-6">
<div style="margin-right:2%;">
<label for="status1">Ban</label>
<label for="status1">Senarai Hitam</label>
</div>
<div class="custom-control custom-switch" >
<input type="checkbox" class="custom-control-input" style="background-color:red !important" name="statusban" id="customSwitch2" onchange="showban(this)">
<label class="custom-control-label" for="customSwitch2" id="txtstatusban"></lable>
<label class="custom-control-label" for="customSwitch2" id="txtstatusban"></label>
</div>
</div>
</div>