I'm a noob at this, please forgive me but I'm trying to connect a one-to-one relationship between a User and BusinessAssumptions
When a user registers:
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$model = BusinessAssumption::create();
$user->businessAssumptions()->save($model);
The user model has the hookup for (BusinessAssumption::class) and the BusinessAssumption has the hookup for (belongsTo)
I'm not getting an error, the application runs just fine but in the database both models have an id to each other but the user doesn't have the assumptions id saved, the assumptions has the user id saved though. I just don't know why the user doesn't persist the model in the database.
I had to migrate the BusinessAssumptions after the User was created
Schema::create('business_assumptions', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->nullable();
$table->timestamps();
});
Schema::table('users', function($table){
$table->integer('business_assumption_id')->nullable();
});
Why isn't the $user->businessAssumptions()->save($model); working?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community