Here are my models:
class BookReading extends Eloquent {
// Book reading has many authors
public function authors()
{
return $this->belongsToMany('Author');
}
}
class Author extends Eloquent {
public function book_readings()
{
return $this->hasMany('BookReading');
}
}
This works:
$book_stores = [1,2,3,4];
$book_readings = BookReading::whereIn('location_id', $book_stores)
->first()->authors()->get()->toJson();
This does not work
$book_readings = BookReading::whereIn('location_id', $book_stores)
->get()->authors()->get()->toJson();
Is there a way to get all book readings and associated authors in one query?
I figured it out:
$book_readings = BookReading::whereIn('location_id', $book_stores)
->with('authors')
->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community