44 lines
1004 B
PHP
44 lines
1004 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master;
|
|
|
|
use App\Enums\Permission;
|
|
use App\Rules\PhoneNumber;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class CustomerRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
$permission = $this->isMethod('POST')
|
|
? Permission::CUSTOMERS_CREATE
|
|
: Permission::CUSTOMERS_UPDATE;
|
|
|
|
return $this->user()?->can($permission->value) ?? false;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'phone_number' => ['nullable', 'string', 'max:20', new PhoneNumber],
|
|
'address' => ['nullable', 'string'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'Nama',
|
|
'phone_number' => 'Nomor Telepon',
|
|
'address' => 'Alamat',
|
|
];
|
|
}
|
|
}
|