58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ConsultantRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('perunding.urus');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$consultantId = $this->route('consultant')?->id;
|
|
|
|
return [
|
|
'nama_perunding' => ['required', 'string', 'max:255'],
|
|
'no_pendaftaran_syarikat' => ['nullable', 'string', 'max:100'],
|
|
'alamat' => ['nullable', 'string', 'max:1000'],
|
|
'emel' => ['nullable', 'email', 'max:255'],
|
|
'telefon' => ['nullable', 'string', 'max:50'],
|
|
'aktif' => ['required', 'boolean'],
|
|
// Maklumat akaun pengguna perunding
|
|
'buat_akaun' => ['nullable', 'boolean'],
|
|
'user_name' => ['nullable', 'required_if:buat_akaun,1', 'string', 'max:255'],
|
|
'user_email' => [
|
|
'nullable', 'required_if:buat_akaun,1', 'email', 'max:255',
|
|
Rule::unique('users', 'email')->ignore($this->route('consultant')?->user_id),
|
|
],
|
|
'user_password' => ['nullable', 'required_if:buat_akaun,1', 'string', 'min:8'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'nama_perunding' => 'nama perunding',
|
|
'no_pendaftaran_syarikat' => 'no pendaftaran syarikat',
|
|
'emel' => 'emel',
|
|
'telefon' => 'telefon',
|
|
'user_name' => 'nama pengguna',
|
|
'user_email' => 'emel akaun',
|
|
'user_password' => 'kata laluan akaun',
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'aktif' => $this->boolean('aktif'),
|
|
'buat_akaun' => $this->boolean('buat_akaun'),
|
|
]);
|
|
}
|
|
}
|