Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Norbertho's avatar

how to modify laravel breeze livewire user reg

Hi,

If i create a new Laravel app and then installing breeze with the Livewire option then i have the following file: views/livewire/pages/auth/register.blade.php this register.blade.php is responsible for registering new users. I would like to add roles to the registration process. So when the user register it will be atomaically saved as customer for this i have a row in my user tabel called "role_id" So my question is how or where can i add this to the registration process?

the register.blade.php file looks like this by default:

{
    public string $name = '';

    public string $email = '';

    public string $password = '';

    public string $password_confirmation = '';

    public function register(): void
    {
        $validated = $this->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class],
            'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
        ]);

        $validated['password'] = Hash::make($validated['password']);

        event(new Registered($user = User::create($validated)));

        auth()->login($user);

        $this->redirect(RouteServiceProvider::HOME, navigate: true);
    }
};
0 likes
1 reply
Snapey's avatar
Snapey
Best Answer
Level 122
    public function register(): void
    {
        $validated = $this->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class],
            'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
        ]);

        $validated['role_id'] = 'customer';  // change this to however you specify customer

        $validated['password'] = Hash::make($validated['password']);

        event(new Registered($user = User::create($validated)));

        auth()->login($user);

        $this->redirect(RouteServiceProvider::HOME, navigate: true);
    }
1 like

Please or to participate in this conversation.