152 lines
4.0 KiB
PHP
152 lines
4.0 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\Verta;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class FlightUpdateRequest 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',
|
|
Rule::unique('flights', 'flight_number')
|
|
->ignore($this->route('flight')),
|
|
],
|
|
|
|
'airline_id' => [
|
|
'required',
|
|
'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',
|
|
'exists:countries,id',
|
|
],
|
|
|
|
'destination_country_id' => [
|
|
'required',
|
|
'exists:countries,id',
|
|
],
|
|
|
|
'origin_city_id' => [
|
|
'required',
|
|
'exists:cities,id',
|
|
'different:destination_city_id',
|
|
],
|
|
|
|
'destination_city_id' => [
|
|
'required',
|
|
'exists:cities,id',
|
|
],
|
|
|
|
'origin_airport_id' => [
|
|
'required',
|
|
'exists:airports,id',
|
|
'different:destination_airport_id',
|
|
],
|
|
|
|
'destination_airport_id' => [
|
|
'required',
|
|
'exists:airports,id',
|
|
],
|
|
|
|
'departure_time' => [
|
|
'required',
|
|
'string',
|
|
function (string $attribute, mixed $value, \Closure $fail) {
|
|
try {
|
|
Verta::parse($value);
|
|
} catch (\Throwable $e) {
|
|
$fail('فرمت زمان حرکت معتبر نیست.');
|
|
}
|
|
},
|
|
],
|
|
|
|
'arrival_time' => [
|
|
'required',
|
|
'string',
|
|
function (string $attribute, mixed $value, \Closure $fail) {
|
|
try {
|
|
$departureTime = Verta::parse($this->input('departure_time'));
|
|
$arrivalTime = Verta::parse($value);
|
|
|
|
if ($arrivalTime->timestamp <= $departureTime->timestamp) {
|
|
$fail('زمان رسیدن باید بعد از زمان حرکت باشد.');
|
|
}
|
|
} catch (\Throwable $e) {
|
|
$fail('فرمت زمان رسیدن معتبر نیست.');
|
|
}
|
|
},
|
|
],
|
|
|
|
'price' => [
|
|
'required',
|
|
'numeric',
|
|
'min:0',
|
|
],
|
|
|
|
'capacity' => [
|
|
'required',
|
|
'integer',
|
|
'min:1',
|
|
],
|
|
|
|
'images' => [
|
|
'nullable',
|
|
'array',
|
|
'max:5',
|
|
],
|
|
|
|
'images.*' => [
|
|
'image',
|
|
'mimes:jpg,jpeg,png,webp',
|
|
'max:800',
|
|
],
|
|
];
|
|
}
|
|
}
|