I want to create one to one relationship in mysql database but I can't find any solution.
User tables:
Author tables:
Schema::create('authors', function(Blueprint $table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
User table
Schema::create('users', function(Blueprint $table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('email');
$table->string('password');
$table->string('remember_token',100)->nullable();
$table->timestamps();
});
And define in model Author:
public function user()
{
return $this->belongs_to('App\User');
}
But when I run php artisan migrate it create one to many relationship in database from users table to author table.
So how to create one to one relationship between them??
Thanks a lot.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community