fix code
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Mission\TransportaionUnit;
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
use App\Models\Mission;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class AllocateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->mission->edare_shahri_id == auth()->user()->edarate_shahri_id && $this->mission->state_id == MissionStates::REQUEST_CREATED->value
|
||||
|| $this->user()?->username === 'witel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'machine_id' => 'required|integer|exists:cmms_machines,id',
|
||||
'driver' => 'required|integer|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$duplicateMission = Mission::query()->where('machine_id', '=', $this->machine_id)
|
||||
->where('start_date', '<=', $this->mission->end_date)
|
||||
->where('end_date', '>=', $this->mission->start_date)
|
||||
->exists();
|
||||
|
||||
if ($duplicateMission) {
|
||||
$validator->errors()->add(
|
||||
'machine_id',
|
||||
'خودروی مورد نظر در این زمان رزرو می باشد'
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user