58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Users;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateUserRequest extends StoreUserRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::check('update', User::class);
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
parent::prepareForValidation();
|
|
|
|
// Set matricule because it is required and not editable.
|
|
/** @var \App\Models\User $userModel */
|
|
$userModel = request()->route()->parameter('user');
|
|
$this->merge([
|
|
'matricule' => $userModel->matricule,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules()
|
|
{
|
|
return array_merge(parent::rules(), [
|
|
'email' => [
|
|
'required',
|
|
'email:rfc,strict,dns,spoof,filter',
|
|
Rule::unique('users', 'email')->ignore(\optional($this->route('user'))->getRouteKey())
|
|
],
|
|
'matricule' => [
|
|
'required',
|
|
'string',
|
|
Rule::unique('users', 'matricule')->ignore(\optional($this->route('user'))->getRouteKey())
|
|
],
|
|
]);
|
|
}
|
|
}
|