48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\V1;
|
|
|
|
use App\Models\Client;
|
|
use App\Rules\Translatable;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* The panel's client form, as rules.
|
|
*/
|
|
class ClientRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$client = $this->route('client');
|
|
$creating = ! $client instanceof Client;
|
|
$sometimes = $creating ? 'required' : 'sometimes';
|
|
|
|
return [
|
|
'name' => [$sometimes, 'string', 'max:255'],
|
|
'slug' => [
|
|
$sometimes,
|
|
'string',
|
|
'max:255',
|
|
'alpha_dash:ascii',
|
|
Rule::unique('clients', 'slug')->ignore($client?->id),
|
|
],
|
|
'sector' => ['sometimes', 'nullable', new Translatable(max: 120)],
|
|
'logo' => ['sometimes', 'nullable', 'string', 'max:2048'],
|
|
'url' => ['sometimes', 'nullable', 'url', 'max:2048'],
|
|
'is_public' => ['sometimes', 'boolean'],
|
|
'position' => ['sometimes', 'integer', 'min:0'],
|
|
];
|
|
}
|
|
}
|