Using Eloquent ORM in Laravel to perform search of database using LIKE

前端 未结 5 1777
清歌不尽
清歌不尽 2020-12-04 15:14

I want to use Eloquent\'s active record building to build a search query, but it is going to be a LIKE search. I have found the User::find($term) or User:

5条回答
  •  一生所求
    2020-12-04 15:41

    If you do not like double quotes like me, this will work for you with single quotes:

    $value = Input::get('q');
    $books = Book::where('name', 'LIKE', '%' . $value . '%')->limit(25)->get();
    
    return view('pages/search/index', compact('books'));
    

提交回复
热议问题