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

43 lines
1.1 KiB
PHP
Raw Normal View History

2022-05-24 17:23:36 +02:00
<?php
namespace App\Http\Requests\Bo;
2022-05-24 17:23:36 +02:00
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
class AssignTicketToUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize()
{
/** @var \App\Models\User */
$user = auth()->user();
return auth()->check() and $user->isAdmin();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'assign' => [
'nullable', 'exists:users,id',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
2022-05-24 17:23:36 +02:00
function ($attribute, $value, $fail) {
/** @var \App\Models\User $user */
if ($user = User::whereId($value)->first() and !$user->isAdmin()) {
$fail(trans('Cet utilisateur ne peut se voir assigner un ticket'));
}
}
]
];
}
}