本文介紹了Laravel 過濾所有列中的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!