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

cameronscott137's avatar

Adding Custom Field to Registration

I've been following the official Spark docs to try and add a custom field to my registration form:

In register-common-form.blade.php:

    <!-- Age -->
    <div class="form-group" :class="{'has-error': registerForm.errors.has('age')}">
        <label class="col-md-4 control-label">Age</label>

        <div class="col-md-6">
            <input type="text" class="form-control" name="age" v-model="registerForm.age">

            <span class="help-block" v-show="registerForm.errors.has('age')">
                @{{ registerForm.errors.get('age') }}
            </span>
        </div>
    </div>

In resources/assets/app.js:

require('spark-bootstrap');

require('./components/bootstrap');

Spark.forms.register = {
    age: ''
};

var app = new Vue({
    mixins: [require('spark')]
});

In SparkServiceProvider.php:

Spark::validateUsersWith(function () {
            return [
                'name' => 'required|max:255',
                'age' => 'required|integer|min:1',
                'email' => 'required|email|max:255|unique:users',
                'password' => 'required|confirmed|min:6',
                'vat_id' => 'max:50|vat_id',
                'terms' => 'required|accepted',
            ];
        });

        Spark::createUsersWith(function ($request) {
            $user = Spark::user();

            $data = $request->all();

            $user->forceFill([
                'name' => $data['name'],
                'email' => $data['email'],
                'age' => $data['age'],
                'password' => bcrypt($data['password']),
                'last_read_announcements_at' => Carbon::now(),
                'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
            ])->save();
            return $user;
        });

That is the exact code from the Spark docs. However, when I fill out my registration form, I receive an error "Something went wrong. Please try again or contact customer support." In the console, I get a 500 error.

Two questions:

  • Is there an obvious mistake in the code above that would cause those errors?
  • Is there an obvious process to begin debugging errors like this? I'm also new to Vue, and my typical Laravel debugging tactics aren't that applicable.
0 likes
4 replies
jmny's avatar

Have you created a DB migration for your new field? Can you check laravel.log for the actual error?

rgillera's avatar

Have you solved this problem? I got this error too. I followed "cookbook - adding registration fields" in spark documentation and i also added column age in DB migration. please help

cameronscott137's avatar

I don't remember the exact issue, but it was something obvious—forgetting to make the attribute mass assignable or similar.

To solve it, though, I do remember checking my laravel.log file in my storage directory. That file contains all the detail you'd come to expect from a typical Laravel error message, so take the steps to recreate your error again, and then check that file. That was enough for me to uncover the root issue.

1 like
rgillera's avatar

Thanks for your help. I solved the problem. I forgot to import Carbon class.

Please or to participate in this conversation.