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

前端 未结 8 1607
小鲜肉
小鲜肉 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 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);
    }
    

提交回复
热议问题