77 lines
2.5 KiB
PHP
77 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\V3\RoadItemsProject;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class StoreRequest 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, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'start_point' => 'required',
|
|
'item_id' => 'required|integer',
|
|
'sub_item_id' => 'required|integer',
|
|
'amount' => 'required|numeric',
|
|
'observed_item_id' => 'integer|exists:observed_items,id',
|
|
'activity_date' => 'required|date_format:Y-m-d',
|
|
'activity_time' => 'required|date_format:H:i',
|
|
'before_image' => 'image|max:4096',
|
|
'after_image' => 'image|max:4096',
|
|
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
|
'rahdaran_id' => 'required|array',
|
|
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'activity_date' => 'تاریخ فعالیت',
|
|
'activity_time' => 'ساعت فعالیت',
|
|
];
|
|
}
|
|
|
|
// public function after(): array
|
|
// {
|
|
// return [
|
|
// function (Validator $validator) {
|
|
// if ($this->has(['item_id', 'sub_item_id'])) {
|
|
//
|
|
// $info_item = InfoItem::query()
|
|
// ->where('item', $this->item_id)
|
|
// ->where('sub_item', $this->sub_item_id)
|
|
// ->firstOrFail();
|
|
//
|
|
// if ($info_item->needs_end_point && !$this->filled('end_point')) {
|
|
// $validator->errors()->add('end_point', __('validation.required'));
|
|
// }
|
|
//
|
|
// if ($info_item->needs_image) {
|
|
// if (!$this->hasFile('before_image')) {
|
|
// $validator->errors()->add('before_image', __('validation.required'));
|
|
// }
|
|
// if (!$this->hasFile('after_image')) {
|
|
// $validator->errors()->add('after_image', __('validation.required'));
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// ];
|
|
// }
|
|
}
|