Php Laravel 5.2-未定义路由的默认错误页

Php Laravel 5.2-未定义路由的默认错误页,php,laravel,laravel-5,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.2,假设我的routes.php中有这样的内容: Route::get('sells', ['as' => 'user_sells', 'uses' => 'SellsController@indexAll']); 现在,如您所知,如果有人打开mySite.com/sells,就会执行控制器中所需的方法 但是,如果有人试图访问一个根本没有定义的路由,比如mySite.com/buys,我想显示一个默认的错误页面。我的意思是,我需要说,如果路线没有定义,显示一个特定的页面 我该怎么做 提

假设我的routes.php中有这样的内容:

Route::get('sells', ['as' => 'user_sells', 'uses' => 'SellsController@indexAll']);
现在,如您所知,如果有人打开mySite.com/sells,就会执行控制器中所需的方法

但是,如果有人试图访问一个根本没有定义的路由,比如mySite.com/buys,我想显示一个默认的错误页面。我的意思是,我需要说,如果路线没有定义,显示一个特定的页面

我该怎么做

提前谢谢

添加: 尝试访问未定义路由时遇到的错误:

哎呀,好像出了什么事

错误异常 C:\wamp\www\codes\laravel5\portpapa\vendor\laravel\framework\src\light\Container\Container.php 第835行:无法解析的依赖项解析[参数#0[ $methods]]类中的照明\路由\路由(视图:


实际上,默认情况下,Laravel已经有了这个功能。如果您在
resources/views
文件夹中创建一个名为
errors/404.blade.php
的视图,这将是自动的

如果要使用自定义代码处理404错误,只需在
App\Exceptions\Handler
类中捕获
NotFoundHttpException
异常:

public function render($request, Exception $e)
{
    if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
        // handle here
        return response()->view('errors.404', [], 404);
    }
}

实际上,默认情况下,Laravel已经有了这个功能。如果您在
resources/views
文件夹中创建一个名为
errors/404.blade.php
的视图,这将是自动的

如果要使用自定义代码处理404错误,只需在
App\Exceptions\Handler
类中捕获
NotFoundHttpException
异常:

public function render($request, Exception $e)
{
    if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
        // handle here
        return response()->view('errors.404', [], 404);
    }
}

如果未定义路由,将抛出NotFoundHttpException。 异常在app/exceptions/handler.php的Larevel中管理

您必须检查异常是否为
NotFoundHttpException
,在这种情况下,返回正确的视图

public function render($request, Exception $e)
{
    if ($this->isHttpException($e))
    {       
        if($e instanceof NotFoundHttpException)
        {
            return response()->view('my.view', [], 404);
        }
        return $this->renderHttpException($e);
    }
    return parent::render($request, $e);
}

.

如果未定义路由,将抛出NotFoundHttpException。 异常在app/exceptions/handler.php的Larevel中管理

您必须检查异常是否为
NotFoundHttpException
,在这种情况下,返回正确的视图

public function render($request, Exception $e)
{
    if ($this->isHttpException($e))
    {       
        if($e instanceof NotFoundHttpException)
        {
            return response()->view('my.view', [], 404);
        }
        return $this->renderHttpException($e);
    }
    return parent::render($request, $e);
}

.

我遇到了这个错误:在类Lightlight\Routing\Route中出现了无法解决的依赖项解析[Parameter#0[$methods]]。我想我可能在某个不应该使用Route的地方使用了Route。我遇到了这个错误:无法解决的依赖项解析[Parameter#0[$methods]]课堂上照明\路由\路由。我想我可能在一些不应该使用路由的地方使用了路由。