42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Auth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rules;
|
|
|
|
class RegisterRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return (bool) config('auth-ui.features.registration');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<mixed>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'username' => [
|
|
'required', 'string', 'max:255', 'alpha_dash',
|
|
function ($attribute, $value, $fail): void {
|
|
if (User::whereRaw('LOWER(username) = ?', [strtolower($value)])->exists()) {
|
|
$fail('The username has already been taken.');
|
|
}
|
|
},
|
|
],
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'last_name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
|
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
|
];
|
|
}
|
|
}
|