ldc-supportweb/app/Http/Requests/Bo/UpdateTicketPriorityRequest.php
2026-01-02 15:31:21 +01:00

57 lines
1.3 KiB
PHP

<?php
namespace App\Http\Requests\Bo;
use App\Models\Ticket;
use Illuminate\Foundation\Http\FormRequest;
class UpdateTicketPriorityRequest extends FormRequest
{
private \App\Models\Ticket $ticket;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->ticket = $this->route('ticket');
$max = Ticket::query()->where('site_id', $this->ticket->site_id)->max('order');
$this->merge([
'priority' => min($this->integer('priority'), $max)
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'priority' => [
'required',
'integer',
'min:1',
function ($attribute, $value, $fail) {
if ($this->ticket && intval($value) === $this->ticket->order) {
$fail("La valeur de {$attribute} doit être différente de la valeur actuelle.");
}
},
],
];
}
}