I have a search form where you can select different cities and a house-type. Can anyone tell me how I can put the entered form data into the URL and display the filtered data with the GET method in Laravel?
Thank you.
I have a search form where you can select different cities and a house-type. Can anyone tell me how I can put the entered form data into the URL and display the filtered data with the GET method in Laravel?
Thank you.
<?php
$selectedcities=[];
if (\Illuminate\Support\Facades\Input::has('city')) {
foreach (\Illuminate\Support\Facades\Input::get('city') as $c) {
$selectedcities[] = $c;
}
}
?>
<script>
$(document).ready(function() {
$('.refine-your-search input[type=checkbox]').click(function() {
var prm = $(this).closest('div').attr('id');
searchByCheckbox(prm);
});
});
function searchByCheckbox(prm) {
var searchString = '';
var searchString = $('#'+prm+'String').val();
if (searchString != '') {
searchString = searchString + '&';
}
var tmpQString = '';
$('#'+prm+' input[type=checkbox]:checked').each(function() {
if(tmpQString != ''){
tmpQString = tmpQString + '&';
}
tmpQString = tmpQString + prm + '[]=' + $(this).val();
});
// alert(tmpQString);
searchString = searchString + tmpQString;
var searchUrl = baseUrl + '?' + searchString;
window.location.replace(searchUrl);
return window.location.href = searchUrl;
}
</script>
<div id='city'>
<!-- use foreach for all cities -->
<input type="checkbox" value="Cityname" name="city[{{ $city->id }}]" {{ (in_array($city->id, $selectedcities)) ? 'checked="checked"' : '' }}>
<label>{{$city->name}}</label>
<input type="hidden" id="cityString" name="cityString" value="<?php echo http_build_query(Request::except(['city']));?>">
<!-- end foreach -->
</div>
<!-- In Controller you can get -->
<?php
$city = $request->city; //and use it in your query LIKE
?>
</div>