重定向到登录获取 404 如果调试为真 拉拉维尔.



所以这是我的web.php

Auth::routes(['verify' => true]);
Route::group(['middleware' => ['auth']], function () {
Route::get('/add/{prod}', 'LandingPageController@addprod')->name('prod.add');
}

如您所见,路由位于auth中间件下,但是如果我尝试在不登录的情况下进行/add/5,如果app.debugtrue404如果它是假的,我会301

登录如果我转储错误,我会得到IlluminateAuthAuthenticationException: Unauthenticated.

编辑

看起来像是由Handler引起的,因为我编辑了一个方法:

public function render($request, Exception $exception)
{
if(config('app.debug')) return parent::render($request, $exception);
else return response()->view('error',array(),404);
}

如何使用我的视图处理错误而不收到此错误?

实现此效果的更简洁方法是修改 Laravel 的异常处理程序。

修改AppExceptionsHandler以捕获每个错误并返回共享的自定义错误页面。

/**
* Render an exception into an HTTP response.
*
* @param  IlluminateHttpRequest  $request
* @param  Exception  $e
* @return IlluminateHttpResponse
*/
public function render($request, Exception $e)
{
if ($e instanceof NotFoundHttpException) {
return response()->view('errors.custom', [], 404);
}
return parent::render($request, $e);
}

可能需要一些自定义才能完全满足您希望将数据传递到共享自定义视图的内容和方式。

相关内容

最新更新