public function getBooks($input)
{
$books= Book::where('book_name', 'LIKE', '%' . $input . '%')->get();
return Response::json($books);
}
我知道如何按给定值过滤列.但是如何按给定值过滤所有列.例如,我有一个名为类别"的列,用户应该能够使用相同的搜索栏来过滤类别.
I know how to filter a column by a given value. But how do I filter ALL columns by a given value. For example, I have a column called 'category' where user should be able to use the same search bar to filter the category.
类似于:
$books = Book::where('all_columns', 'LIKE', '%' . $input . '%')->get();
谢谢!
大多数数据库不支持同时搜索所有列.恐怕您可能不得不将所有列链接在一起:
Most databases do not support searching all columns simultaneously. I'm afraid you'll likely have to chain all of the columns together:
$books = Book::where('book_name', 'LIKE', '%' . $input . '%')
->orWhere('another_column', 'LIKE', '%' . $input . '%')
// etc
->get();
这篇关于Laravel 过滤所有列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!