I never used spark before, but from reading the docs I think you need to do that in the SparkServiceProviderclass
Where do I place validation & storage code when adding registration fields?
I'm looking at this documentation: https://spark.laravel.com/docs/6.0/adding-registration-fields
I've managed to modify the view and added the extra JS needed however I'm having trouble with the 'Validation & Storage' section.
Where do I add the code that is being referenced? For example this example PHP block is given:
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',
];
});
I'm just wondering where the correct places are for these bit's of PHP though?
Not sure if this makes much of a difference but I installed Spark via composer as the default installer wouldn't work.
Thanks, Nick
According to the documentation you need to do this in your service provider
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;
});
Alternatively you can use classes for this
Spark::validateUsersWith('UserValidator@validate');
Spark::createUsersWith('UserCreator@create');
Please or to participate in this conversation.