C
C
chelkaz2016-03-15 22:30:09
Laravel
chelkaz, 2016-03-15 22:30:09

Laravel 5 Models. Is it right to simplify the query?

It is necessary to search in all fields. I do this
$ResultSearch = ListAirport::where(function ($q) use ($search_value) {
$q->where('name_one', 'like', "%{$search_value}%")
->orWhere('sity ', 'like', "%{$search_value}%")
->orWhere('name_en', 'like', "%{$search_value}%")
->orWhere('code', 'like', "% {$search_value}%")
->orWhere('key', 'like', "%{$search_value}%")
->orWhere('airport_name', 'like', "%{$search_value}%");
})->get();
return response()->json($ResultSearch);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-03-15
@chelkaz

Everything is fine here, you just need to escape the request
$search_value = addcslashes($search_value, '%_');

A
Andrzej Wielski, 2016-03-15
@wielski

I advise you to use Eloquence Searchable for searching
https://github.com/jarektkaczyk/eloquence/wiki/Bui...
It is possible to use relevant fulltext search, you can search by links, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question