ldc-gen-game-web/app/Http/Requests/Bo/Users/UpdateUserRequest.php
noah.lancien 218a3a7891 phpstan
2024-01-31 09:03:18 +00:00

66 lines
1.7 KiB
PHP

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