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

SteamDiesel's avatar

Spark: register new user with seperate preferences model

Hey team,

I've got a Shiny new spark project, I'm trying to include a new entry for a realted UserPresets model when I create a new User. I've prefer to keep UserPresets seperate to the User model for sanity and so my app remains seperate to the spark billing and user control.

Has anyone else found a good spot to wedge a $user->presets->create(['user_id'=>$user->id]); into the spark register new user labrynth?

0 likes
5 replies
steve_laracasts's avatar

I don't think you should try and keep anything separate. Learn how Spark works, the whole point is that it is a starter pack that you build on not around. It looks intimidating, but it's not so bad, the Vue 2 course here on Laracasts will help if you haven't done that.

Up to you of course, but I would just follow the Adding Registration Fields and Adding Profile Fields guidelines in the docs.

SteamDiesel's avatar

@KEL_ - I see what you're saying, and if it were as simple as a few fields that stay static I'd probably agree. But I want to give the user the ability to make and switch between multiple preset profiles, the first of which will be their default.

steve_laracasts's avatar
Level 7

I see :)

Are you changing the sign up procedure at all?

If not, why not just make your preset profile selection the first thing a user does from the dashboard after they register/login, that way you can just write it as a normal Laravel application and largely ignore Spark.

If this is no good then there are several places you could do this, but Spark::swap on the register method in the RegisterController is probably the way to go, add something like this to the booted method of your SparkServiceProvider

    Spark::swap(
        Register::class . '@handle', 
        function($requestl){
            // replacement method here
        }
    );

I haven't done this yet, but it will be something like that, you will probably want to copy the Spark code and just add in your own bit :)

SteamDiesel's avatar

Thinking about it now... I agree, I could put it straight onto the landing-dashboard so it prompts them to do it first-order-of-business.

on the front end run something like: if ( !$presets ) { show preset form }

But also I could do the same IF check and, instead of rendering a form which the user could ignore and then I risk breaking their first time user experience, I could just run the create method when rendering the dashboard for the first time.

so in the back end on the route to return the '/home' view I can put: if ( !$presets ) {$presets = $user->presets ->create([ app default settings ])}

I'm much more confident with the vanilla Laravel or Vuejs than I am with Spark. Spark is magic.

But I like your suggestion to get to know Spark better. I'll tinker with the Spark::swap and see what I can achieve. Thanks for your help! :)

steve_laracasts's avatar

Hey @steamdiesel

That's cool - all makes sense, sounds like you are on your way again - and yes there are so many ways to do the same thing.

Spark is fine once you get over the initial hurdles - hey, I'm doing it on some level so it can't be that hard heh ;)

If you already know Laravel and Vue I think you may surprise yourself if you just start reading the code and researching or asking here about the things you don't understand. I found this Laracasts a great refresher on how to read and understand code:

How to read code

I feel like there's only a few of us who are vocal on here and are using Spark; it would be good to get some more discussion about it going, help each other work out the best practice with it all, etc... it would be awesome to have someone who really knows what they are doing to call on.

Anyway - good luck - hope it works out for you :)

Would you be so kind as to mark a 'best answer' for me please?

Please or to participate in this conversation.