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

Kriptic's avatar

Registration Error

If I register an event listener and attach it to UserRegistered in sparkserviceproviders, then, when registering a new user at domain.com/register, it redirects to domain.com/undefined.

Some interesting things I noticed about this in the last 4 hours :(

inf Laravel\Spark\Http\Controllers\Auth\RegisterController;


    /**
     * Handle a registration request for the application.
     *
     * @param  RegisterRequest  $request
     * @return Response
     */
    public function register(RegisterRequest $request)
    {        
        dd("hi");
        Auth::login($user = Spark::interact(
            Register::class, [$request]
        ));

        event(new UserRegistered($user));

        return response()->json([
            'redirect' => $this->redirectPath()
        ]);
    }
}

...does NOT register a user, and serves up the /undefined error.. dd("hi) is nowhere to be found...

And..


    /**
     * Handle a registration request for the application.
     *
     * @param  RegisterRequest  $request
     * @return Response
     */
    public function register(RegisterRequest $request)
    {        

        Auth::login($user = Spark::interact(
            Register::class, [$request]
        ));

        dd("hi");
        event(new UserRegistered($user));

        return response()->json([
            'redirect' => $this->redirectPath()
        ]);
    }
}

...successfully registers a new user in the DB, but still redirects to /undefined, nobody said hi.

and finally if I do

        Auth::login($user = Spark::interact(
            Register::class, [$request]
        ));

        event(new UserRegistered($user));

        dd("hi");

        return response()->json([
            'redirect' => $this->redirectPath()

and....

        Auth::login($user = Spark::interact(
            Register::class, [$request]
        ));

        event(new UserRegistered($user));

    return 'hey';

        return response()->json([
            'redirect' => $this->redirectPath()

Still. registers a user, but I end up at /undefined again. No dd dump screen at all.

I feel like the answer is here somewhere... I did manage to find the point at which dd("hi") actually says hi, it is pretty deep in httpexception classes, I forget exaclty where now.

MY QUESTION

I suppose I could fix this, just, don't use events on register.

Maybe I'm doing something wrong in the events... but, I tested just putting dd("hi") in my events, and they DO NOT show up.


<?php

namespace App\Providers;



use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        // User Related Events...
        'Laravel\Spark\Events\Auth\UserRegistered' => [            
            'Laravel\Spark\Listeners\Subscription\CreateTrialEndingNotification',                   

    //MY EVENT
            'App\Listeners\SendRegistrationEmails',            
            
        ],
    
...


And, for good measure...


<?php

namespace App\Listeners;

use Auth;
use Mail;
use Carbon\Carbon;
use App\Mail\ConfirmEmail;
use App\Mail\UserRegister;
use App\RegistrationConfirmation;
use App\Mail\SponsorSaleNotification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Laravel\Spark\Events\Auth\UserRegistered;

class SendRegistrationEmails
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  UserRegistered  $event
     * @return void
     */
    public function handle(UserRegistered $event)
    {       

        // add a new link to confirm table
        RegistrationConfirmation::create([
            'email' => $event->user->email,
            'token' => str_random(32),   
            'created_at' => Carbon::now(),         
            ]);

        dump("In send register email listener, sending confirm email, welcome email and sponsor notif email");


        Mail::to($event->user)->send(new UserRegister($event->user));
        // sleep(1);
        Mail::to($event->user)->send(new ConfirmEmail($event->user)); 
        // sleep(1);
        Mail::to($event->user)->send(new SponsorSaleNotification($event->user)); 

               

        // Mail::to($this->user())->queue($this->UserRegister());
        //use user-registered framework to send it?
        
    }
}

All of this works, I get the emails, the new table row is inserted, it's all good.

But . ARGH. my users getting sent to /undefined is not cool.

Help please if you know.

Thanks.

0 likes
3 replies
Kriptic's avatar

to be clear:

        dump("In send register email listener, sending confirm email, welcome email and sponsor notif email");



does not show in the browser, but the other logic works.

there's something going on at a high level here I think...

Kriptic's avatar

woops, I apologize.. this:

If I register an event listener and attach it to UserRegistered in sparkserviceproviders, then, when registering a new user at domain.com/register, it redirects to domain.com/undefined.

is wrong. It's App/Providers/EventServiceProvider

Kriptic's avatar

Yeah, I tried everything.

I decided to check if user is on first login in the /home controller, then process the code I wanted to run.

Not ideal, but works for now.

If anyone has experience with this specifically, registering pretty much ANY event in spark causes this error, let me know.

Might be a bug in spark? No custom event registration?

Please or to participate in this conversation.