49 lines
1 KiB
PHP
49 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Rules\HasMinimumRole;
|
|
use App\Rules\IsValidRole;
|
|
use App\User;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class DestroyUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
$this->merge([
|
|
'minimumrole' => optional(User::whereId($this->created_by)->first())->role ?? null
|
|
]);
|
|
return auth()->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'created_by' => 'required|exists:users,id',
|
|
'minimumrole' => [new IsValidRole(), new HasMinimumRole('CONTRIBUTEUR')]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'minimumrole' => trans('rôle')
|
|
];
|
|
}
|
|
}
|