2024-04-16 10:32:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Ranges;
|
|
|
|
|
|
|
|
|
|
use App\Models\Range;
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
|
|
class UpdateSubmodelsOrderRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return Gate::check('reorderSubmodels', Range::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'newValues' => json_decode($this->input('jsonValue'), true),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$currentRange = request('range');
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-04-16 10:32:26 +02:00
|
|
|
return [
|
2024-04-25 10:43:44 +02:00
|
|
|
'jsonValue' => 'json',
|
|
|
|
|
'newValues' => 'required|array',
|
|
|
|
|
'newValues.*' => 'required|array',
|
|
|
|
|
'newValues.*.id' => 'required|exists:subranges,id',
|
2024-04-16 10:32:26 +02:00
|
|
|
'newValues.*.range_id' => function (string $attribute, mixed $value, \Closure $fail) use ($currentRange) {
|
2024-06-19 12:06:56 +02:00
|
|
|
if ($value !== $currentRange->getKey()) {
|
2024-04-16 10:32:26 +02:00
|
|
|
$fail("The {$attribute} is invalid.");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|