Support the ongoing development of Laravel.io →
Authentication
Last updated 1 year ago.
0

You are getting relationships mixed up on controllers versus models. Your relationships go on your model, so you Sponsor model would look like

Class Sponsor extends Model
{
  protected $table = 'sponsors';

  public function user()
  {
    return $this->hasOne('App\User');
  }
}

Anyway, there are a lot of different ways to do what you are asking, so the easiest is to work with two different models (the user and the sponsor). you would probably have another input for the user's password (lets say <input type="text" name="user_password">) So in your "store" method you first create the user

$user = \App\User::create([
  'email' =>$request->input('email'),
  'password' => \Hash::make($request->input('user_password')
]);

Now that you have the user created, you can either a) add the additional field to what you have, or b) if you have a relationship setup use that.

$sponsor = new Sponsor;
$sponsor->user_id = $user->id;
$sponsor->first_name = $request->input('first_name');
// rest of it
$sponsor->save();

I suggest you do a tiny bit more reading on relationships and try out php artisan tinker to play around (it loads up your laravel project but gives you a command line to run commands like \App\User::all()).

Docs: https://laravel.com/docs/5.3/eloquent-relationships

Video: https://laracademy.co/videos/blast-off-with-laravel/eloquent-r...

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

superrupe superrupe Joined 27 Sep 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.