104 lines
2.4 KiB
PHP
104 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use App\Enums\Admin\AdminRole;
|
|
use App\Enums\Admin\AdminStatus;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class AdminUpdateRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$admin = $this->route('admin');
|
|
return [
|
|
'first_name' => [
|
|
'required',
|
|
'string',
|
|
'max:64',
|
|
'persianAlpha',
|
|
],
|
|
|
|
'last_name' => [
|
|
'required',
|
|
'string',
|
|
'max:64',
|
|
'persianAlpha',
|
|
],
|
|
|
|
'username' => [
|
|
'required',
|
|
'string',
|
|
'min:3',
|
|
'max:100',
|
|
'regex:/^[a-zA-Z][a-zA-Z0-9_]*$/',
|
|
Rule::unique('admins', 'username')->ignore($admin),
|
|
],
|
|
|
|
'email' => [
|
|
'nullable',
|
|
'string',
|
|
'email',
|
|
'max:150',
|
|
Rule::unique('admins', 'email')->ignore($admin),
|
|
],
|
|
|
|
'mobile' => [
|
|
'nullable',
|
|
'string',
|
|
'regex:/^09\d{9}$/',
|
|
'ir_mobile:zero',
|
|
Rule::unique('admins', 'mobile')->ignore($admin),
|
|
],
|
|
'password' => [
|
|
'nullable',
|
|
'string',
|
|
'min:8',
|
|
'max:255',
|
|
],
|
|
|
|
'role' => [
|
|
'nullable',
|
|
Rule::enum(AdminRole::class),
|
|
],
|
|
|
|
'status' => [
|
|
'nullable',
|
|
Rule::enum(AdminStatus::class),
|
|
],
|
|
|
|
'permissions' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
|
|
'permissions.*' => [
|
|
'required',
|
|
'string',
|
|
],
|
|
|
|
'image' => [
|
|
'nullable',
|
|
'image',
|
|
'mimes:jpg,jpeg,png,webp',
|
|
'max:800',
|
|
],
|
|
];
|
|
}
|
|
}
|