I want to make when user search by country on the page refresh eg. result page to keep selected country on the option on the form.
This is what I have where I populate the dropdown
@foreach ($countries as $country)
<option value="{!! $country->id !!}">{!! $country->name !!}</option>
@endforeach
And this is what I have tried but seems that is not correct since the value isn't selected
@foreach ($countries as $country)
<option value="{!! $country->id !!}" @if( old('country->id') == $country->id) selected="selected" @endif>{!! $country->name !!}</option>
@endforeach
What's the trick here?
Here is the controller
public function search(Request $request)
{
$searchText = strip_tags($request['q']);
$seachLocation = strip_tags($request['l']);
$columns =['alias','description','address1','address2','address3'];
$query = Item::select('*');
$query->where( 'title', 'like', '%'.$searchText.'%');
foreach( $columns as $column) {
$query->orWhere( $column, 'like', '%'.$searchText.'%', '%'.$seachLocation.'%');
}
$query->orWhereHas('category',function( $query ) use ( $searchText ) {
$query->where('title', 'like', '%'.$searchText.'%' );
});
$query->orWhereHas('country',function( $query ) use ( $searchText ) {
$query->where('name', 'like', '%'.$searchText.'%' );
});
$items = $query->paginate(5);
$searchQuery = $searchText;
$searchQueryLoc = $seachLocation;
return view('search', compact('items','searchQuery','seachLocation'));
}