O'Reilly logo
  • GIL EG thinks this is interesting:

));

  // oops! wrong author!

  $book = Book::where('title', '=', 'The Alchemist')->first();
  $rightAuthor = Author::where('first_name', '=', 'Paulo')->where('last_name', '=', 'Coelho')->first();

  // done!
  $righ

From

Cover of Learning Laravel's Eloquent

Note

associate() to add id to the related hasMany model