php – LARAVEL – >为什么尝试在Laravel中不起作用?

前端之家收集整理的这篇文章主要介绍了php – LARAVEL – >为什么尝试在Laravel中不起作用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在RouteServiceProvider中有代码

$router->bind('user',function ($value) {
    try{
        throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
    }catch(Exception $e){
        exit('nott');
    }
});

而且我没有提出输出

nott

我正进入(状态

Sorry,the page you are looking for could not be found.
NotFoundHttpException in RouteServiceProvider.PHP line 75:
...

编辑:
这有效:

$router->bind('user',function ($value) {
    try{
        throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
    }catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
        exit('addd');
    }
});

但这不起作用:

$router->bind('user',function ($value) {
    try{
        return (new User)->findOrFail(122);
    }catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
        exit('addd');
    }
});

解决方法

$router->bind('user',function ($value) {
    try{
        throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
    }catch(\Exception $e){
        exit('nott');
    }
});

要么

use Exception; //on top

    $router->bind('user',function ($value) {
        try{
            throw (new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException);
        }catch(Exception $e){
            exit('nott');
        }
    });

我想现在你明白你错过了什么.

猜你在找的Laravel相关文章