Hello everyone.
I have a search box where the user will enter the business name and a dropdown where the user will select the state/province as shown in the dropdown. The business model has a relationship with the Province model.
How I can do a search based on province only. if user leaves a search bar empty and only select province I want to show all the businesses based on states/provinces.
here is my:
Index view:
<form method="get" action="{{route('search.business')}}">
<div class="inner-form">
<div class="input-field first-wrap">
<input type="text" placeholder="What are you looking for?" name="search" />
</div>
<div class="input-field second-wrap">
<select name="search" id="" class="form-control" style="height:inherit;">
@foreach ($provinces as $province)
<option value="{{$province->id}}">{{$province->name}}</option>
@endforeach
</select>
</div>
<div class="input-field third-wrap">
<button class="btn-search" type="submit">Search</button>
</div>
</div>
</form>
my search controller
public function search(Request $request)
{
$businesses = Business::with('provinces')
->where('name', 'LIKE', '%' . $request->input('search') . '%')
->paginate(10);
// dd($businesses);
return view('front-end.search-details', compact('businesses'));
}
plz, tell me a query for the province to this is my first time to use search functionality that's why I am stuck here.