我有一个搜索表单,您可以在其中选择不同的城市和房屋类型。谁能告诉我如何将输入的表单数据放入URL并在Laravel中使用GET方法显示过滤后的数据?
谢谢。
答案 0 :(得分:0)
<?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>
&#13;
<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>
&#13;
<!-- In Controller you can get -->
<?php
$city = $request->city; //and use it in your query LIKE
?>
答案 1 :(得分:0)
希望它给你一些想法
查看强>
{!! Form::open(['url' => ['yoururl'], 'method' => 'get', 'role' => 'form' ,'id' => 'search']) !!}
<select class="form-control" name="city">
<option value="">--Select--</option>
@foreach($cityas $cs)
<option value="{{$cs['cityid']}}">{{$cs['city']}}</option>
@endforeach
</select>
<input type="text" name="zip" class="form-control fldcls clrfield">
<input type="hidden" id="hasvalues" name="search" value="1">
<button type="button" onclick="submitSearch()" class="btn rsi-submit-btn">Search</button>
{!! Form::close() !!}
<强>脚本强>
function submitSearch(){
$("#search").submit();
}
<强>控制器强>
在您的控制器中
public function functionname(Request $request)
if($request->input('search') && $request->input('search') == '1'){
$result = modalname::modal function name( $request );
//Get the data using modal and passed it to the view page
}
$data['result'] = $result;
return view('your view page', $data);
}