Files
usermanagement/app/Http/Requests/User.php
Daeng Deni Mardaeni 47f248c7b3 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
2024-08-28 09:09:29 +07:00

56 lines
1.5 KiB
PHP

<?php
namespace Modules\Usermanagement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Hash;
class User extends FormRequest
{
public function authorize()
{
return true;
}
/**
* Returns an array of validation rules for the registration form.
*
* @return array The validation rules.
*/
public function rules()
: array
{
$rules = [
'name' => 'required|string|max:255',
'branch_id' => 'nullable|exists:branches,id',
'profile_photo_path' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
];
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;
}
public function passedValidation()
{
if ($this->password!=='') {
$this->merge([
'password' => Hash::make($this->password),
]);
}
}
}