Have you created a DB migration for your new field? Can you check laravel.log for the actual error?
Jun 21, 2016
4
Level 3
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.
Please or to participate in this conversation.