@JOSHUAF Did you include the form input registration in /resources/assets/js/app.js before the Vue instance?
Added new registration field, getting error
I followed the directions on the spark site to the best of my knowledge, but still got an error. All I wish to do is to add a username field.
I have added the entry in the migrations database. I have also verified that the required data is indeed sent to the server via the request.
The error is
ErrorException in TeamRepository.php line 35: Trying to get property of non-object
It appears that the data for the user is either not being passed properly, or the user isn't being created properly.
Here are the first few lines from the log
in TeamRepository.php line 35 at HandleExceptions->handleError('8', 'Trying to get property of non-object', '/home/vagrant/Code/vendor/laravel/spark/src/Repositories/TeamRepository.php', '35', array('user' => null, 'data' => array('name' => 'teamDefault'))) in TeamRepository.php line 35 at TeamRepository->create(null, array('name' => 'teamDefault')) at call_user_func_array(array(object(TeamRepository), 'create'), array(null, array('name' => 'teamDefault'))) in CallsInteractions.php line 56 at Spark::interact('Laravel\Spark\Contracts\Repositories\TeamRepository@create', array(null, array('name' => 'teamDefault'))) in CreateTeam.php line 58 at CreateTeam->handle(null, array('name' => 'teamDefault')) at call_user_func_array(array(object(CreateTeam), 'handle'), array(null, array('name' => 'teamDefault'))) in CallsInteractions.php line 56 at Spark::interact('Laravel\Spark\Contracts\Interactions\Settings\Teams\CreateTeam@handle', array(null, array('name' => 'teamDefault'))) in Register.php line 58
Additionally, I found the instructions to be difficult to understand in some ways. Why does the addition of a parameter require the need for totally new functions like 'createUsersWith' instead of just adding items? Why do we need to include items lime the name, email, terms, etc? Do we need to include them or is that just redundant? If we need to include them, why not the rest of the parameters?
Addition to the view
<!-- User Name -->
<div class="form-group" :class="{'has-error': registerForm.errors.has('username')}">
<label class="col-md-4 control-label">User Name</label>
<div class="col-md-6">
<input type="username" class="form-control" name="username" v-model="registerForm.username" autofocus>
<span class="help-block" v-show="registerForm.errors.has('username')">
@{{ registerForm.errors.get('username') }}
</span>
</div>
</div>
app.js
Spark.forms.register = { username:'' };
SparkServiceProvider
Spark::validateUsersWith(function () {
return [
'team' => 'required',
'name' => 'required|min:5|max:255',
'username' => 'required|min:5|max:255|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
];
});
Spark::createUsersWith(function ($request) {
$user = Spark::user();
$data = $request->all();
$user->forceFill([
'team' => $data['team'],
'name' => $data['name'],
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'last_read_announcements_at' => Carbon::now(),
'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
]);
});
Spark is an app that provides user registration among other things, so user registration is part of the core code of Spark. Spark provides an easy way to alter this without having to override all of the methods involved in creating users, by providing these 'helpers' for common changes.
That being said, it looks like you're just forgetting to persist and return the user.
In your Spark::createUsersWith method, you need to save and return like this:
//...
'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays())])->save();
return $user;
});
Please or to participate in this conversation.