Files
shahrzadzandi09/app/Http/Requests/AirportStoreRequest.php
T

86 lines
2.4 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class AirportStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
// کد فرودگاه همیشه با حروف بزرگ ذخیره شود (IATA)
if ($this->has('code')) {
$this->merge([
'code' => strtoupper($this->input('code')),
]);
}
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' =>
[
'required',
'string',
'max:150'
],
'city' =>
[
'required',
'string',
'max:100'
],
'province' =>
[
'required',
'string',
'max:100'
],
'code' =>
[
'required',
'string',
'max:10'
],
];
}
public function attributes(): array
{
return [
'name' => 'نام فرودگاه',
'city' => 'شهر',
'country' => 'کشور',
'code' => 'کد فرودگاه',
];
}
// public function messages(): array
// {
// return [
// 'name.required' => 'نام فرودگاه الزامی است.',
// 'name.max' => 'نام فرودگاه حداکثر ۱۵۰ کاراکتر باشد.',
// 'city.required' => 'نام شهر الزامی است.',
// 'city.max' => 'نام شهر حداکثر ۱۰۰ کاراکتر باشد.',
// 'country.required' => 'نام کشور الزامی است.',
// 'country.max' => 'نام کشور حداکثر ۱۰۰ کاراکتر باشد.',
// 'code.required' => 'کد فرودگاه (IATA) الزامی است.',
// 'code.max' => 'کد فرودگاه حداکثر ۱۰ کاراکتر باشد.',
// ];
// }
}