Support the ongoing development of →
Last updated 2 years ago.

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

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()).



Last updated 7 years ago.

Sign in to participate in this thread!


Your banner here too?

superrupe superrupe Joined 27 Sep 2016


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

Your logo here?

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

© 2024 - All rights reserved.