public function searchBook(Request $request, $dep, $bTitleAuthor)
{
if($request->ajax()) {
$books = Book::where('department_id', $dep)
->where(function($query) {
$query->where('title', 'like', '%'.$bTitleAuthor.'%')
->orWhere('author', 'like', '%'.$bTitleAuthor.'%');
});
}
}
This is what i saw on Laravel page, but in their example they used raw values. I am using parameters from the function and $bTitleAuthor
giving me error that it is an "undefined variable".
In the end, I want to achieve something like this:
SELECT * FROM books
WHERE department_id = '$dep'
AND (
WHERE title LIKE '$bTitleAuthor'
OR author LIKE '$bTitleAuthor'
);