feat(admin): implement full flight management for panel admin
This commit is contained in:
@@ -2,8 +2,14 @@
|
||||
|
||||
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
|
||||
{
|
||||
@@ -12,7 +18,7 @@ class FlightStoreRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +29,112 @@ class FlightStoreRequest extends FormRequest
|
||||
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user