本文介紹了Laravel 過濾所有列中的值的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
public function getBooks($input)
{
$books= Book::where('book_name', 'LIKE', '%' . $input . '%')->get();
return Response::json($books);
}
我知道如何按給定值過濾列.但是如何按給定值過濾所有列.例如,我有一個(gè)名為類別"的列,用戶應(yīng)該能夠使用相同的搜索欄來過濾類別.
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();
謝謝!
推薦答案
大多數(shù)數(shù)據(jù)庫不支持同時(shí)搜索所有列.恐怕您可能不得不將所有列鏈接在一??起:
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();
這篇關(guān)于Laravel 過濾所有列中的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!