54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\V3\Mission\Violation;
|
|
|
|
use App\Enums\MissionStates;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class UpdateRequest 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|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'enter_time' => 'required|date',
|
|
'end_km'=> 'required|string',
|
|
];
|
|
}
|
|
|
|
public function after(): array
|
|
{
|
|
return [
|
|
function (Validator $validator) {
|
|
if (strtotime($this->enter_time) < strtotime($this->violation->exit_time)) {
|
|
$validator->errors()->add(
|
|
'time',
|
|
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
|
|
);
|
|
}
|
|
if ($this->end_km < $this->violation->km) {
|
|
$validator->errors()->add(
|
|
'end_km',
|
|
'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.'
|
|
);
|
|
}
|
|
}
|
|
];
|
|
}
|
|
}
|