Update Module Users

- Fix Form Validation for Check Password, if null password not changed
- Update Validation NIK on Update user data
- Fix Role Not Assign if value is id not role name
- Change User Migration, change password field to nullable
This commit is contained in:
Daeng Deni Mardaeni 2024-08-28 09:09:29 +07:00
parent 18b8ed5344
commit 47f248c7b3
3 changed files with 12 additions and 8 deletions

View File

@ -22,18 +22,20 @@
{
$rules = [
'name' => 'required|string|max:255',
'nik' => 'nullable|string|max:6|unique:users,nik',
'branch_id' => 'nullable|exists:branches,id',
'profile_photo_path' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
];
if ($this->password || $this->method() === 'POST') {
$rules['email'] = 'required|email|unique:users,email';
if ($this->password) {
$rules['password'] = 'required|string|min:8|confirmed';
}
if ($this->method() === 'PUT') {
$rules['email'] = 'required|email|unique:users,email,' . $this->id;
$rules['nik'] = 'nullable|string|max:6|unique:users,nik,' . $this->id;
} else {
$rules['email'] = 'required|email|unique:users,email';
$rules['nik'] = 'nullable|string|max:6|unique:users,nik';
}
return $rules;
@ -41,9 +43,11 @@
public function passedValidation()
{
$this->merge([
'password' => Hash::make($this->password),
]);
if ($this->password!=='') {
$this->merge([
'password' => Hash::make($this->password),
]);
}
}
}

View File

@ -16,7 +16,7 @@ return new class extends Migration
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('password')->nullable();
$table->rememberToken();
$table->timestamps();
$table->softDeletes();

View File

@ -159,7 +159,7 @@
</div>
</div>
<div class="switch switch-sm">
<input {{ in_array($role->name,Auth()->user()->roles->pluck('name')->toArray()) ? 'checked' : '' }} name="roles" type="radio" value="{{ $role->id }}">
<input {{ in_array($role->name,Auth()->user()->roles->pluck('name')->toArray()) ? 'checked' : '' }} name="roles" type="radio" value="{{ $role->name }}">
</div>
</div>
@endforeach