add code validation
This commit is contained in:
@@ -5,6 +5,7 @@ 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 StartRequest extends FormRequest
|
||||
{
|
||||
@@ -13,7 +14,7 @@ class StartRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return ($this->mission->state_id == MissionStates::PENDING_CONFIRMATION->value && $this->mission->code == $this->code);
|
||||
return $this->mission->state_id == MissionStates::PENDING_CONFIRMATION->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,4 +28,18 @@ class StartRequest extends FormRequest
|
||||
'code' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
if ($this->mission->code != $this->code){
|
||||
$validator->errors()->add(
|
||||
'code',
|
||||
'کد وارد شده صحیح نمی باشد'
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class StoreRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
if ($this->type === 1){
|
||||
if ($this->type == 1){
|
||||
$start = Carbon::parse($this->start_date);
|
||||
$end = Carbon::parse($this->end_date);
|
||||
|
||||
|
||||
@@ -71,11 +71,12 @@ class Mission extends Model
|
||||
|
||||
public function roadObserved(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(RoadObserved::class,
|
||||
return $this->morphedByMany(
|
||||
RoadObserved::class,
|
||||
'missionable',
|
||||
'missionables',
|
||||
'mission_id',
|
||||
'missionable_id',
|
||||
'missionable_id'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ class ControlUnitService
|
||||
allowedSelects: [
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time'
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time',
|
||||
'code', 'category_id', 'category_name', 'explanation'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ class TransportationUnitService
|
||||
allowedSelects: [
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time'
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time',
|
||||
'code', 'category_id', 'category_name', 'explanation'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user