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

61 lines
1.7 KiB
PHP
Raw Permalink Normal View History

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