Laravel Eloquent Relationships

One to One

One to one relationships are very straightforward in Laravel. Make sure that one of the tables has a key that references the id of the other table.

For example, an addresses table will have a field called user_id. That will reference the field. Eloquent will handle the rest.

// app/User.php


public function address() {
    return     his->hasOne('App\Address');


To save a one-to-one relationship:


Like this article? Follow @chrisoncode on Twitter