ldc-legaulois/app/Http/Requests/Bo/Ranges/UpdateSubmodelsOrderRequest.php

49 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?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
return [
2024-04-25 10:43:44 +02:00
'jsonValue' => 'json',
'newValues' => 'required|array',
'newValues.*' => 'required|array',
'newValues.*.id' => 'required|exists:subranges,id',
'newValues.*.range_id' => function (string $attribute, mixed $value, \Closure $fail) use ($currentRange) {
if ($value !== $currentRange->getKey()) {
$fail("The {$attribute} is invalid.");
}
},
];
}
}