How do I catch exceptions / missing pages in Laravel 5?

前端 未结 8 1514
小鲜肉
小鲜肉 2020-11-27 13:11

In Laravel 5, App::missing and App::error is not available, so how do your catch exceptions and missing pages now?

I could not find any inf

相关标签:
8条回答
  • 2020-11-27 13:58

    Laravel ships with default error page, You can easily add custom error pages like this

    1 - Create an error view in view -> errors folder
    2 - The name must match HTTP errors like 404 or 403 500

    `Route::get('/page/not/found',function($closure){
      // second param is  optional 
      abort(404, 'Page Not found');
    });`
    
    0 讨论(0)
  • 2020-11-27 14:00

    Angular HTML5 mode could cause a bunch of missing pages (user bookmark few page and try to reload). If you can't override server settings to handle that, you might thinking of override missing page behaviour.

    You can modify \App\Exceptions\Handler render method to push content with 200 rather than push 404 template with 404 code.

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($this->isHttpException($e) && $e->getStatusCode() == 404)
        {
            return response()->view('angular', []);
        }
        return parent::render($request, $e);
    }
    
    0 讨论(0)
提交回复
热议问题