Php 404 Laravel 5.2.15中的错误处理
我问这个问题是因为我在这个问题中添加了我的评论之后没有得到回复 在上面的答案中,我们可以看到下面要在Php 404 Laravel 5.2.15中的错误处理,php,laravel-5.1,laravel-5.2,Php,Laravel 5.1,Laravel 5.2,我问这个问题是因为我在这个问题中添加了我的评论之后没有得到回复 在上面的答案中,我们可以看到下面要在filters.php中使用的代码 App::missing(function($exception) { return Response::view('errors.missing', array(), 404); }); 但是,我认为最新版本中没有filters.php。有人能提出更好的方法来处理404错误吗?您不需要再这样做了。不要包括那个。您要做的是将名为404.blade.p
filters.php中使用的代码
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
但是,我认为最新版本中没有filters.php
。有人能提出更好的方法来处理404错误吗?您不需要再这样做了。不要包括那个。您要做的是将名为404.blade.php
的视图文件(您的404错误视图)放入resources/views/errors
文件夹中,Laravel将为您处理404错误。您不再需要这样做了。不要包括那个。您要做的是将名为404.blade.php
的视图文件(404错误视图)放入resources/views/errors
文件夹中,Laravel将为您处理404错误。看一看
我只是更改了这行App/Exceptions/Handler.php文件
public function render($request, Exception $e)
{
// the below code is for Whoops support. Since Whoops can open some security holes we want to only have it
// enabled in the debug environment. We also don't want Whoops to handle 404 and Validation related exceptions.
if (config('app.debug') && !($e instanceof ValidationException) && !($e instanceof HttpResponseException))
{
/******************here I changed**********************/
# return $this->renderExceptionWithWhoops($e);
return response()->view('errors.404', [], 404);
}
// this line allows you to redirect to a route or even back to the current page if there is a CSRF Token Mismatch
if($e instanceof TokenMismatchException){
return redirect()->route('index');
}
// let's add some support if a Model is not found
// for example, if you were to run a query for User #10000 and that user didn't exist we can return a 404 error
if ($e instanceof ModelNotFoundException) {
return response()->view('errors.404', [], 404);
}
// Let's return a default error page instead of the ugly Laravel error page when we have fatal exceptions
if($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) {
return \Response::view('errors.500',array(),500);
}
// finally we are back to the original default error handling provided by Laravel
if($this->isHttpException($e))
{
switch ($e->getStatusCode()) {
// not found
case 404:
return \Response::view('errors.404',array(),404);
break;
// internal error
case 500:
return \Response::view('errors.500',array(),500);
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
/******************here I changed**********************/
#return parent::render($request, $e);
}
if (config('app.debug') && !($e instanceof ValidationException) && !($e instanceof HttpResponseException))
{
看一看
我只是更改了这行App/Exceptions/Handler.php文件
public function render($request, Exception $e)
{
// the below code is for Whoops support. Since Whoops can open some security holes we want to only have it
// enabled in the debug environment. We also don't want Whoops to handle 404 and Validation related exceptions.
if (config('app.debug') && !($e instanceof ValidationException) && !($e instanceof HttpResponseException))
{
/******************here I changed**********************/
# return $this->renderExceptionWithWhoops($e);
return response()->view('errors.404', [], 404);
}
// this line allows you to redirect to a route or even back to the current page if there is a CSRF Token Mismatch
if($e instanceof TokenMismatchException){
return redirect()->route('index');
}
// let's add some support if a Model is not found
// for example, if you were to run a query for User #10000 and that user didn't exist we can return a 404 error
if ($e instanceof ModelNotFoundException) {
return response()->view('errors.404', [], 404);
}
// Let's return a default error page instead of the ugly Laravel error page when we have fatal exceptions
if($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) {
return \Response::view('errors.500',array(),500);
}
// finally we are back to the original default error handling provided by Laravel
if($this->isHttpException($e))
{
switch ($e->getStatusCode()) {
// not found
case 404:
return \Response::view('errors.404',array(),404);
break;
// internal error
case 500:
return \Response::view('errors.500',array(),500);
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
/******************here I changed**********************/
#return parent::render($request, $e);
}
if (config('app.debug') && !($e instanceof ValidationException) && !($e instanceof HttpResponseException))
{