55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\V3\Mission\ControlUnit;
|
|
|
|
use App\Enums\MissionStates;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class FinishRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->mission->state_id == MissionStates::START_MISSION->value;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$mission = $this->route('mission');
|
|
return [
|
|
'time' => 'required|date',
|
|
'end_km' => 'required',
|
|
];
|
|
}
|
|
|
|
public function after(): array
|
|
{
|
|
return [
|
|
function (Validator $validator) {
|
|
$mission = $this->route('mission');
|
|
if (strtotime($this->time) < strtotime($mission->start_time)) {
|
|
$validator->errors()->add(
|
|
'time',
|
|
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
|
|
);
|
|
}
|
|
if ($this->end_km < $mission->km) {
|
|
$validator->errors()->add(
|
|
'end_km',
|
|
'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.'
|
|
);
|
|
}
|
|
}
|
|
];
|
|
}
|
|
}
|