使用laravel 5.6和mysql。我的表名称为vehicles
id name categoryname brandname model districtname
1 juy car toyota 121 coba
2 gty van nissan caravan natai
3 bgh car bmw 520d zenso
4 hyu van ford max mizuri
5 nhj car toyota 121 nakaga
6 gtr car toyota corolla wassa
7 gtr van nissan caravan goa
我具有以下控制器功能来过滤请求型号,
$vehicles = Vehicle::with('uploads')
->when(request('modelname'), function ($query, $request) {
return $query->where('modelname', request('modelname'));
})
->orderBy('adtype','DESC')
和用于显示上述数据的“我的刀片”链接是
<a href="{{ route('vehicles.modelindex') }}?modelname={{$dis->modelname}}{{$dis->modelname}}</a>
和路线
Route::get('modelname', [
'uses' => 'VehicleController@indexmodel',
'as' => 'vehicles.modelindex',
]);
但是现在我还需要使用型号名称作为过滤器区名,然后将刀片链接更改为
<a href="{{ route('vehicles.modelindex') }}?modelname={{$dis->modelname}}?districtname={{$dis->districtname}}">{{$dis->modelname}}</a>
和类似的控制器
$vehicles = Vehicle::with('uploads')
->when(request('modelname'), function ($query, $request) {
return $query->where('modelname', request('modelname'));
})
->when(request('districtname'), function ($query, $request) {
return $query->where('districtname',request('districtname'));
})
->orderBy('adtype','DESC')
但是现在当我单击上面的新链接URL时,
http://localhost:8000/modelname?modelname=Highlander%20Hybrid?districtname=newyork
,但不显示任何结果。显示刀片视图的结果是
@forelse( $vehicles as $vehicule )
@if( $vehicule->uploads->count() > 0 )
<a href="{{ route('vehicles.show', $vehicule->id) }}">
@php
$upload = $vehicule->uploads->sortByDesc('id')->first();
@endphp
Vehicle Model Name: {{$vehicule->modelname}}
<div style="border-style: solid; background-color: {{ $vehicule->adtype === 1 ? '#FFEFD5' : '#FFFFFF' }} ">
<img src="/images/{{ $upload->resized_name }}" height="150" width="250"></a>
<label> {{ Carbon\Carbon::parse($vehicule->created_at)->diffForHumans()}} </label>
<label> {{$vehicule->provincename}}</label>
<label> {{$vehicule->milage}}</label>
@endif
@empty
<td>Sorry,No Advertisment to display.</td>
@endforelse
但是单击带有模型名称和地区名称的新链接时,页面仅显示Sorry,No Advertisment to display
如何解决此问题?
答案 0 :(得分:1)
我首先要注意的是您构建get请求的方式。如果将参数附加到请求,则第一个参数使用?
串联,但随后的每个参数都应使用&
。
因此您的网址应如下所示:
<a href="{{ route('vehicles.modelindex') }}?modelname={{$dis->modelname}}&districtname={{$dis->districtname}}">{{$dis->modelname}}</a>