Reputation: 1
I am new to Laravel and maybe somebody can give me an example for this.
I have two tables - Auhors
and Books
and two views - authors.index
and books.index
.
I know how to display all the books related to author in authors.index, but the question is, how to display all authors related books in books.index
view?
My models and BookController:
Upvotes: 0
Views: 47
Reputation: 418
You need to use the opposite function belongsTo
into your Books
model.
public function authors() {
return $this->belongsTo(Authors::class, 'author_id', 'id');
}
You can find more info here
Upvotes: 0