This is my code:
$query = Book::query();
if (isset($input['alphabet']))
$query->where('name', 'LIKE', $input['alphabet'] . '%');
if (isset($input['status']))
$query->where('status', $input['status']);
if (isset($input['genre']))
$query->with(array('genres' => function($q) use($input) {
$q->where('genres.id', $input['genre']);
}));
I want to get all books with name LIKE .... and status = ....
Queries 1 and 2 (name, status) are OK. But the query 3 (genres) is not work.
Book - Genres (Many to many relationship).