ldc-supportweb/app/Http/Requests/Bo/ChangeTicketStatus.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-04-18 20:31:07 +02:00
<?php
namespace App\Http\Requests\Bo;
2021-04-18 20:31:07 +02:00
use App\Enums\Tickets\TicketStatusEnum;
2021-04-18 20:31:07 +02:00
use Illuminate\Foundation\Http\FormRequest;
class ChangeTicketStatus extends FormRequest
{
2021-05-18 19:33:36 +02:00
/**
* Determine if the user is authorized to make this request.
*
2022-03-29 16:57:54 +02:00
* @return boolean
2021-05-18 19:33:36 +02:00
*/
public function authorize(): bool
2021-05-18 19:33:36 +02:00
{
2021-07-23 11:04:09 +02:00
/** @var \App\Models\User */
$user = auth()->user();
return auth()->check() and $user->isAdmin();
2021-05-18 19:33:36 +02:00
}
2021-04-18 20:31:07 +02:00
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
2021-04-18 20:31:07 +02:00
{
return [
'status' => [
'required',
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
2021-04-18 20:31:07 +02:00
function ($attribute, $value, $fail) {
if (!in_array($value, TicketStatusEnum::toValues())) {
2021-04-18 20:31:07 +02:00
$fail(__('Veuillez choisir entre :values', [
'value' => implode(',', TicketStatusEnum::toLabels())
2021-04-18 20:31:07 +02:00
]));
}
}
],
];
}
}