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

mniblett's avatar

Confused by "Adding Registration Fields" documentation

First, I am basically a hobbyist coder and new to Laravel in general, so you may need to dumb it down a bit for me. I am confused about the way to go about adding new fields in the registration as described here in spark.laravel.com/docs/1.0/adding-registration-fields. Going through the steps: no issues with modifying the view, I get that. In extending the javascript I guess we are just adding a new variable to the javascript so it picks it up from the form and passes it along. Ok.

Where I am getting lost is the validation and storage part. In the Spark::validateUsersWith method (and Spark::createUsersWith method as well) it seems like we are recreating logic that is already built in (everything but the new field). Are we basically replacing an existing method somewhere with these whole new ones (which I guess is identical except for our added field)? How come we don't just go to those methods and add the new fields directly to them? And, where do I put these two methods, inside booted()?

Lastly, don't we need to update the create-users_table migration? Does that happen automatically somehow or is it just assumed that everyone will know to do that? Oh, and don't we need to make the new field "fillable" in user.php?

Thanks!

0 likes
2 replies
christian_H's avatar
Level 1

For your first question, yeah you're basically recreating those same functions with your extra fields added. I believe this is because you're not supposed to modify the base spark code that's in the "spark" directory because it could get overwritten when you update to the newest version of spark. It would probably still work if you just modified the existing functions, but doing it this way ensures that you're still able to safely update your application. And yes, you put those inside booted().

For your question about the create_users_table migration, you might want to take a look at the docs for migrations (https://laravel.com/docs/5.2/migrations). Have you already run the migration (php artisan migrate)? If you haven't, then you can add the fields you need and then migrate. If you have already run it, you'll need to create a new migration that adds your new fields to the existing users table. And yeah, you should go ahead and make the new field fillable in the model.

mniblett's avatar

Thanks for the help Christian. I think I'm up on the migration process (I was actually going to roll it back, then add the field to the users table, and re-do the migration since I don't have any data that needs to be preserved). Have a great day!

Please or to participate in this conversation.