Files
laravel-nuxt-ui-inertia-tem…/app/Http/Requests/Profile/UpdateProfileRequest.php

48 lines
1.3 KiB
PHP

<?php
namespace App\Http\Requests\Profile;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateProfileRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* @return array<string, array<mixed>>
*/
public function rules(): array
{
return [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'username' => [
'required',
'string',
'max:255',
'alpha_dash',
function ($attribute, $value, $fail): void {
if (User::whereKeyNot($this->user()->getKey())
->whereRaw('LOWER(username) = ?', [strtolower($value)])
->exists()) {
$fail('The username has already been taken.');
}
},
],
'email' => [
'required',
'string',
'lowercase',
'email',
'max:255',
Rule::unique(User::class)->ignore($this->user()->getKey()),
],
];
}
}