ldc-supportweb/app/Http/Requests/Bo/AssignTicketToUserRequest.php
2025-04-23 12:24:31 +02:00

42 lines
1.1 KiB
PHP

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