ldc-tregalette/app/Http/Requests/Bo/Users/UpdateUserRequest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2023-12-15 15:53:55 +00:00
<?php
namespace App\Http\Requests\Bo\Users;
2023-12-15 17:23:54 +01:00
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rule;
2023-12-15 15:53:55 +00:00
use Illuminate\Validation\Rules\Password;
class UpdateUserRequest extends StoreUserRequest
{
2023-12-15 17:23:54 +01:00
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
2024-01-26 16:24:14 +01:00
public function authorize(): bool
2023-12-15 17:23:54 +01:00
{
return Gate::check('update', $this->route('user'));
}
2023-12-15 15:53:55 +00:00
/**
* Prepare the data for validation.
*
* @return void
*/
2024-01-26 16:24:14 +01:00
protected function prepareForValidation(): void
2023-12-15 15:53:55 +00:00
{
$this->merge([
2024-01-26 16:24:14 +01:00
'published' => $this->boolean('published'),
'password' => $this->input('password') ??
\optional($this->route('user'))->password,
2023-12-15 17:23:54 +01:00
'password_confirmation' => $this->input('password_confirmation') ??
2024-01-26 16:24:14 +01:00
\optional($this->route('user'))->password
2023-12-15 15:53:55 +00:00
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return array_merge(parent::rules(), [
2024-01-26 16:24:14 +01:00
'email' => [
2023-12-15 15:53:55 +00:00
'required',
'email:rfc,strict,dns,spoof,filter',
2024-01-26 16:24:14 +01:00
Rule::unique('users', 'email')->ignore(\optional($this->route('user'))->getRouteKey())
2023-12-15 15:53:55 +00:00
],
'password' => [
'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8)
->letters()
->mixedCase()
->numbers()
->symbols()
->uncompromised()
],
]);
}
}