Support the ongoing development of Laravel.io →
Database Eloquent Installation

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?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

redferret redferret Joined 30 Jan 2017

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.

© 2025 Laravel.io - All rights reserved.