简体   繁体   English

Laravel 5.3中的Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException

[英]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.

相关问题 Laravel 4错误Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Laravel 4 Error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel错误Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException - Laravel error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel中的Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException错误 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Error in Laravel Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException Laravel - Symfony\Component\HttpKernel\Exception\NotFoundHttpException Laravel Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException Laravel 4.1 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel 4.1 Laravel 错误 8 Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel error 8 Symfony\Component\HttpKernel\Exception\NotFoundHttpException Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Symfony\Component\HttpKernel\Exception\NotFoundHttpException Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel “消息”:“”,“异常”:“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”,“文件”: - Laravel “message”: “”, “exception”: “Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”, “file”: 无法在 Laravel 上捕获“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException” - Can not catch "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" on laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM