49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreInstitutionRequest extends FormRequest
|
|
{
|
|
/**
|
|
* L'autorizzazione (solo Admin) è gestita dal middleware di rotta.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Default per i campi con valore di colonna (color, is_storage_place):
|
|
* così non si inseriscono mai NULL su colonne NOT NULL.
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->mergeIfMissing([
|
|
'color' => '#c5cae9',
|
|
'is_storage_place' => true,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'category_id' => ['required', 'integer', 'exists:institution_categories,id'],
|
|
'name' => ['required', 'string', 'max:255', 'unique:institutions,name'],
|
|
'abbreviation' => ['required', 'string', 'max:5', 'unique:institutions,abbreviation'],
|
|
'address' => ['required', 'string', 'max:255'],
|
|
'city' => ['required', 'string', 'max:100'],
|
|
'lat' => ['required', 'numeric', 'between:-90,90'],
|
|
'lon' => ['required', 'numeric', 'between:-180,180'],
|
|
'logo' => ['required', 'image', 'max:5120'],
|
|
'color' => ['required', 'string', 'max:50'],
|
|
'is_storage_place' => ['required', 'boolean'],
|
|
];
|
|
}
|
|
}
|