Laravel Eloquent Relationships

One to Many

To define a one to many relationship, the database setup is the same as one-to-one relationships. Make sure that one of the tables has a key that references the id of the other table.

For example, a posts table will have a field called user_id. That will reference the users.id field. Eloquent will handle the rest.

// app/User.php

...

public function posts() {
    return $this->hasMany('App\Post');
}

...

To save a one-to-many relationship:

$user->posts()->saveMany($posts);