I'm currently trying to customize a search bar that filters the results of two tables, a book and a category .
I have an installation relationship for both models, where:
Book.php (Model) (table: id, b_name, b_author, cat_id)
public function bookCategory()
{
return $this->belongsTo('Category', 'cat_id', 'id');
}
Category.php (Model) (table: id, cat_name)
public function book()
{
return $this->hasMany('Book', 'cat_id', 'id');
}
BookController.php
public function getFilterBooks($input)
{
$books = Book::with('bookCategory')->where('**cat_name at category table**. 'LIKE', '%' . $input . '%'')->get();
return Response::json($books);
}
But obviously this will not work. The reason I do this is because I want to allow users to use the same search bar to filter different columns (that I know how to do this in one table, but not in two or more).