141 lines
3.6 KiB
PHP
141 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Flight;
|
|
|
|
use App\Enums\Flight\FlightScope;
|
|
use App\Enums\Flight\FlightStatus;
|
|
use App\Enums\Flight\FlightTripType;
|
|
use App\Enums\Flight\FlightType;
|
|
use Hekmatinasser\Verta\Facades\Verta;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class FlightStoreRequest 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
|
|
{
|
|
return [
|
|
'flight_number' => [
|
|
'required',
|
|
'string',
|
|
'max:20',
|
|
'unique:flights,flight_number',
|
|
],
|
|
|
|
'airline_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:airlines,id',
|
|
],
|
|
|
|
'flight_scope' => [
|
|
'required',
|
|
Rule::enum(FlightScope::class),
|
|
],
|
|
|
|
'flight_type' => [
|
|
'required',
|
|
Rule::enum(FlightType::class),
|
|
],
|
|
|
|
'trip_type' => [
|
|
'required',
|
|
Rule::enum(FlightTripType::class),
|
|
],
|
|
|
|
'status' => [
|
|
'required',
|
|
Rule::enum(FlightStatus::class),
|
|
],
|
|
|
|
'origin_country_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:countries,id',
|
|
],
|
|
|
|
'destination_country_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:countries,id',
|
|
],
|
|
|
|
'origin_city_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:cities,id',
|
|
'different:destination_city_id'
|
|
],
|
|
|
|
'destination_city_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:cities,id',
|
|
],
|
|
|
|
'origin_airport_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:airports,id',
|
|
'different:destination_airport_id',
|
|
],
|
|
|
|
'destination_airport_id' => [
|
|
'required',
|
|
'integer',
|
|
'exists:airports,id',
|
|
],
|
|
'departure_time' => ['required', 'string'],
|
|
'arrival_time' => [
|
|
'required',
|
|
'string',
|
|
function ($attribute, $value, $fail) {
|
|
$departure = $this->input('departure_time');
|
|
if ($departure && Verta::parse($value)->datetime() <= Verta::parse($departure)->datetime()) {
|
|
$fail('زمان رسیدن باید بعد از زمان حرکت باشد.');
|
|
}
|
|
},
|
|
],
|
|
'price' => [
|
|
'required',
|
|
'integer',
|
|
'min:0',
|
|
],
|
|
|
|
'capacity' => [
|
|
'required',
|
|
'integer',
|
|
'min:1',
|
|
'max:1000',
|
|
],
|
|
|
|
'images' => [
|
|
'nullable',
|
|
'array',
|
|
'max:5',
|
|
],
|
|
|
|
'images.*' => [
|
|
'file',
|
|
'image',
|
|
'mimes:jpg,jpeg,png,webp',
|
|
'max:800',
|
|
],
|
|
];
|
|
}
|
|
}
|