I have db tables 'books','book_authors' . And when user search in website for 'John Doe How to be happy' for example. I wanna search from db for author with name 'John' or 'Doe' or book with title'How to be happy'.
$books = Book::where('book_title','like', '%'.$search.'%')
->orWhereHas('authors', function (Builder $q) use ($search) {
$q->where('name', 'like','%'.$search.'%')
})->paginate(12);
Here my query . But It looks for author with name 'John Doe How to be happy' or for books with title 'John Doe How to be happy' . And results nothing . Is it possible ?