2024-08-07 01:47:07 +00:00
|
|
|
<?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 = [
|
2024-08-27 07:45:50 +00:00
|
|
|
'name' => 'required|string|max:255',
|
|
|
|
'branch_id' => 'nullable|exists:branches,id',
|
|
|
|
'profile_photo_path' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
2024-09-19 07:49:13 +00:00
|
|
|
'sign' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
2024-08-07 01:47:07 +00:00
|
|
|
];
|
|
|
|
|
2024-09-19 07:49:13 +00:00
|
|
|
if ($this->password !==null) {
|
2024-08-07 01:47:07 +00:00
|
|
|
$rules['password'] = 'required|string|min:8|confirmed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->method() === 'PUT') {
|
|
|
|
$rules['email'] = 'required|email|unique:users,email,' . $this->id;
|
2024-08-28 02:09:29 +00:00
|
|
|
$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';
|
2024-08-07 01:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function passedValidation()
|
|
|
|
{
|
2024-09-19 07:49:13 +00:00
|
|
|
if ($this->password !== null) {
|
2024-08-28 02:09:29 +00:00
|
|
|
$this->merge([
|
|
|
|
'password' => Hash::make($this->password),
|
|
|
|
]);
|
|
|
|
}
|
2024-08-07 01:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|