[英]Symfony\Component\HttpKernel\Exception\NotFoundHttpException in Laravel 5.3
Previously I had trouble with route precedence with helps and suggestions I overcame it by adding regex in my route. 以前,我在使用帮助和建议来解决路由优先级方面遇到麻烦,我在路由中添加了regex来克服了它。 Now my route is this:
现在我的路线是这样的:
Route::get('/{country}/{category}', ['as' => 'tour.list', 'uses' => 'LinkController@tourlist'])
->where('country', '[A-Za-z]+')->where('category', '[A-Za-z]+');
Route::get('/{category}/{slug}',['as' => 'single.tour', 'uses' => 'LinkController@singleTour'])
->where('category', '[A-Za-z]+')->where('category', '[w\d\-\_]+');
with this route I get error an error of: 用这条路线我得到一个错误的错误:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
When I remove regex from first route I'm getting same problem as before and when I remove regex from 2nd route I get an error of: 当我从第一条路线中删除正则表达式时,我遇到了与以前相同的问题;当我从第二条路线中删除正则表达式时,出现了以下错误:
Trying to get property of non-object
(View: F:\project\resources\views\public\tours\show.blade.php)
My methods in LinkController are: 我在LinkController中的方法是:
public function tourlist($country, $category){
$tour = Tour::whereHas('category', function($q) use($category) {
$q->where('name','=', $category);
})
->whereHas('country', function($r) use($country) {
$r->where('name','=', $country);
})
->get();
return view('public.tours.list')->withTours($tour);
}
public function singleTour($slug,$category)
{
$tour = Tour::where('slug','=', $slug)
->whereHas('category', function($r) use($category) {
$r->where('name','=', $category);
})
->first();
return view('public.tours.show')->withTour($tour);
}
And my code in view is: 我认为的代码是:
<a href="{{ route('single.tour',['category' => $tour->category->name, 'slug' => $tour->slug]) }}">{{$tour->title}}</a>
Change you Regex 更改您的正则表达式
where('category', '[w\\d\\-\\_]+');
to where('slug', '[A-Za-z\\d\\-\\_]+');
到
where('slug', '[A-Za-z\\d\\-\\_]+');
The above would solve the initial problem of the route not working properly. 以上将解决路由无法正常工作的最初问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.