ldc-supportweb/app/Http/Requests/ChangeTicketStatus.php
2021-05-18 19:33:36 +02:00

42 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Enums\TicketStatus;
use Illuminate\Foundation\Http\FormRequest;
class ChangeTicketStatus extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check() and
auth()->user()->role === 1;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'status' => [
'required',
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if (!in_array($value, TicketStatus::toValues())) {
$fail(__('Veuillez choisir entre :values', [
'value' => implode(',', TicketStatus::toLabels())
]));
}
}
],
];
}
}