Created
November 15, 2018 15:47
-
-
Save Regis011/80b464113be66ae4c643dc9a0cc2ebbc to your computer and use it in GitHub Desktop.
Laravel - search controller function for multiple keywords and long text in form query. Eloquent search query filters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function search(Request $request) | |
| { | |
| $res = (new BestCategory)->newQuery(); | |
| $q = $request->q; | |
| $q = explode(' ', $q); | |
| $res->where('title', 'like', '%'.$q[0].'%')->orWhere('description', 'like', '%'.$q[0].'%'); | |
| for ($i=1; $i < count($q); $i++) { | |
| $res->orWhere('title', 'like', '%'.$q[$i].'%'); | |
| $res->orWhere('description', 'like', '%'.$q[$i].'%'); | |
| } | |
| return $res->get(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment