Laravel 没有抛出错误而是重定向到登录

时间:2021-03-05 14:22:49

标签: laravel

在我的 Laravel 项目中,我遇到了以下无法隔离的行为以及非常烦人的行为,例如当我向控制器发送请求并且路由或控制器不存在时,Laravel 既不记录错误也不显示错误,而是总是重定向到登录页面 - 我已经搜索了很多,我可能在项目中配置错误,但无法找出问题所在。

我的 Laravel 版本:7.3.4 系统:视窗 服务器:Wamp with Apache 2.4.39,Mysql 5.7.26,Php 版本:7.3.5

路由/网络

// Route url
Route::get('/', 'DashboardController@dashboard');
//.. custom routes
Auth::routes();

控制器看起来像这样

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DashboardController extends Controller
{

  public function __construct()
  {
    $this->middleware('auth');
  }


  // Dashboard - Ruwido
  public function dashboard(){
    $pageConfigs = [
      'pageHeader' => false
    ];

    return view('/pages/dashboard', [
      'pageConfigs' => $pageConfigs
    ]);
  }

}

错误处理程序

<?php

namespace App\Exceptions;

use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Throwable  $exception
     * @return void
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Throwable $exception)
    {
        return parent::render($request, $exception);
    }
}

有人遇到过这样的问题吗?

1 个答案:

答案 0 :(得分:0)

您正在构造函数中使用中间件身份验证,如果用户未通过身份验证,它将重定向到登录,并且不会让请求在仪表板方法中继续进行。如果用户通过身份验证检查您的默认防护,可能它指向 api 身份验证,现在您正在使用 api auth,它将不会通过会话进行身份验证,而是使用 api 令牌;首先尝试在构造函数中注释掉中间件;

相关问题