'Laravel - Retrieve specific data from pivot table
I am implemeting a search using Laravel, but couldn't figure out how to get data from my pivot table. The pivot is a many to many relationship between Books and Tags.
The idea here is to search books by tags and display them.
class Book extends Model
{
public function tags() {
return $this->belongsToMany(Tag::class);
}
}
class Tag extends Model
{
public function books() {
return $this->belongsToMany(Book::class);
}
}
Other search seems to work just fine.
$books = Book::where('title', 'LIKE', '%'.$search_text.'%')
->orWhere('author', 'LIKE', '%'.$search_text.'%')
->orWhere('editor', 'LIKE', '%'.$search_text.'%')
->orWhere('ISBN', 'LIKE', '%'.$search_text.'%')
->orWhere('year', 'LIKE', '%'.$search_text.'%')
->orWhere('language', 'LIKE', '%'.$search_text.'%')
->get();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
