I’m refreshing my laravel skills because it has been 2 years since I used it. I would say some things have changed and I’m struggling with some of those.
I want to register users and looking at Laravel Breeze tutorials, it can already be done with just the default setup which comes with Breeze.
However, I’m not able to register a new user because of an error message I get for all my fields, telling me the field is required. Well, I can assure you I do fill out the form with correct data but it would still give me the error and it seems I’m the only one who bumps into this issue..
My Blade file:
<x-guest-layout>
<form method="POST" action="{{ route('register') }}">
@csrf
<!-- Name -->
<div>
<x-input-label for="name" :value="__('Name')" class="text-white" />
<x-text-input id="name" class="block mt-1 w-full bg-gray-100 border-b-0" type="text" name="name" :value="old('name')" required autofocus autocomplete="name" />
<x-input-error :messages="$errors->get('name')" class="mt-2" />
</div>
<!-- Username | This will be visible to the public -->
<div class="mt-4">
<x-input-label for="username" :value="__('Username')" class="text-white" />
<x-text-input id="username" class="block mt-1 w-full bg-gray-100 border-b-0" type="text" name="username" :value="old('username')" required autofocus autocomplete="username" />
<x-input-error :messages="$errors->get('username')" class="mt-2" />
</div>
<!-- Email Address -->
<div class="mt-4">
<x-input-label for="email" :value="__('Email')" class="text-white" />
<x-text-input id="email" class="block mt-1 w-full bg-gray-100 border-b-0" type="email" name="email" :value="old('email')" required autocomplete="username" />
<x-input-error :messages="$errors->get('email')" class="mt-2" />
</div>
<!-- Password -->
<div class="mt-4">
<x-input-label for="password" :value="__('Password')" class="text-white" />
<x-text-input id="password" class="block mt-1 w-full border-b-0"
type="password"
name="password"
required
autocomplete="new-password" />
<x-input-error :messages="$errors->get('password')" class="mt-2" />
</div>
<!-- Confirm Password -->
<div class="mt-4">
<x-input-label for="password_confirmation" :value="__('Confirm Password')" class="text-white" />
<x-text-input id="password_confirmation" class="block mt-1 w-full border-b-0"
type="password"
name="password_confirmation"
required
autocomplete="new-password" />
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
</div>
<div class="flex items-center justify-end mt-4">
<a class="underline text-sm text-gray-600 dark:text-white hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('login') }}">
{{ __('Already registered?') }}
</a>
<x-primary-button class="ms-4">
{{ __('Register') }}
</x-primary-button>
</div>
</form>
</x-guest-layout>
My RegisteredAuthController
<?php
namespace AppHttpControllersAuth;
use AppHttpControllersController;
use AppModelsUser;
use IlluminateAuthEventsRegistered;
use IlluminateHttpRedirectResponse;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;
use IlluminateSupportFacadesHash;
use IlluminateValidationRules;
use IlluminateViewView;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*/
public function create(): View
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @throws IlluminateValidationValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', RulesPassword::defaults()],
]);
dd('halllooooooo');
$user = User::create([
'name' => $request->name,
'username' => $request->username,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
dd($user);
event(new Registered($user));
Auth::login($user);
return redirect(route('dashboard', absolute: false));
}
}
If you want to see me reproduce the steps you can watch this loom:
https://www.loom.com/share/d6bf15d9d3ff46929cbad9ba41fb2019?sid=5515dcee-80db-4fff-9613-cdfb446bfbc9