Answer the question
In order to leave comments, you need to log in
How to do Laravel search?
How can I search in Laravel using one form in several fields and in one field?
Now the search method looks like this:
public function search(Request $request)
{
$result = DB::table('ads')
->where('city', $request->city)
->orWhere('category', $request->cat)
->get();
dd($result);
}
Answer the question
In order to leave comments, you need to log in
How to make friends in Laravel 5 where()->orWhere and whereIn()?
$cityId = $request->input('city_id');
$categoryId = $request->input('category_id');
$adverts = Advert::when($cityId, function ($query, $cityId) {
$query->where('city_id', $cityId);
})
->when($categoryId, function ($query, $categoryId) {
$query->where('category_id', $categoryId);
})
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question