ldc-gen-game-web/app/Http/Requests/Bo/Users/UpdateUserRequest.php

67 lines
1.7 KiB
PHP
Raw Permalink Normal View History

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