[Vuejs]-Laravel Spark โ€“ Adding additional fields to registration form, but when empty no errors are returned

0๐Ÿ‘

โœ…

Okay I finally stumbled across it ๐Ÿ˜€

In Laravel\Spark\Interactions\Auth\CreateUser.php there is a $rules method like so:

public function rules($request)
    {
        return [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
            'vat_id' => 'max:50|vat_id',
            'terms' => 'required|accepted',
        ];
    }

All I have done is add my username field, and it works brilliantly!

public function rules($request)
    {
        return [
            'name' => 'required|max:255',
            'username' => 'required|unique:users',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
            'vat_id' => 'max:50|vat_id',
            'terms' => 'required|accepted',
        ];
    }
๐Ÿ‘คAndy Holmes

0๐Ÿ‘

Above answer is just for validation rules you also need to navigate to spark\src\Repositories\UserRepository.php and add 'username' => $data['username'], to the create() method like this:

public function create(array $data)
{
    $user = Spark::user();

    $user->forceFill([
        'name' => $data['name'],
        'username' => $data['username'], // ADDED THIS
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'confirmation_code' => str_random(30),
        'last_read_announcements_at' => Carbon::now(),
        'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
    ])->save();

    return $user;
}

Leave a comment