42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
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.FoundInExtendedClassBeforeLastUsed
|
|
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'));
|
|
}
|
|
}
|
|
]
|
|
];
|
|
}
|
|
}
|