88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Hekmatinasser\Verta\Verta;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class TourStoreRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the userController 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
|
|
{
|
|
return [
|
|
'title' => [
|
|
'required',
|
|
'string',
|
|
'max:150'
|
|
],
|
|
'travel_type_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:travel_types,id'
|
|
],
|
|
'summary' => [
|
|
'nullable',
|
|
'string',
|
|
'max:255'
|
|
],
|
|
'description' => [
|
|
'nullable',
|
|
'string'
|
|
],
|
|
'price' => [
|
|
'required',
|
|
'numeric',
|
|
'min:0'
|
|
],
|
|
'departure_date' => [
|
|
'required',
|
|
'string',
|
|
function ($attribute, $value, $fail) {
|
|
|
|
try {
|
|
$gregorian = Verta::parse($value)
|
|
->formatGregorian('Y-m-d');
|
|
} catch (\Exception $e) {
|
|
$fail('تاریخ حرکت معتبر نیست.');
|
|
return;
|
|
}
|
|
|
|
if ($gregorian < now()->format('Y-m-d')) {
|
|
$fail('تاریخ حرکت نمیتواند قبل از تاریخ امروز باشد.');
|
|
}
|
|
},
|
|
],
|
|
'image' => [
|
|
$this->isMethod('put') || $this->isMethod('patch') ? 'nullable' : 'required',
|
|
'image',
|
|
'mimes:jpg,jpeg,png,webp',
|
|
'max:2048'
|
|
],
|
|
'views' => [
|
|
'nullable',
|
|
'integer',
|
|
'min:0'
|
|
],
|
|
'status' => [
|
|
'required',
|
|
'in:0,1,2'
|
|
]
|
|
|
|
];
|
|
}
|
|
}
|