【问题标题】:Removing redirect for specific route groups删除特定路由组的重定向
【发布时间】:2019-08-21 00:03:51
【问题描述】:

我希望创建一个路由组,使特定用户无需经过身份验证即可查看我网站上的信息。

目前,我创建了一个名为“public”的路由服务提供商,如下所示:

Route::get('customer/application', function () {
    return view('customerview.customer-application');
});

当我写 'php artisan route:list' 时,路线会出现以下内容:

方法:GET |头 URL:客户/应用程序 中间件:''

我已删除所有中间件以试图绕过身份验证,但没有成功。

将我重定向到登录页面的区域在 App\Exceptions\Handler.php 中:

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    return redirect()->guest('login');
}

我也尝试将路线分配给“访客”组,但没有帮助。如何绕过不同组的返回redirect()->guest('login');

【问题讨论】:

  • 你能提供你的路由文件吗?因为如果您不对任何组应用中间件或身份验证检查,未经身份验证的用户将可以看到它,我假设您已将 Auth::routes() 放在路由文件中的任何组之外。
  • 检查你的 RouteServiceProvider.php 可能是你在那里添加中间件。
  • 在定义这条路线之前,您是否打电话给Route::auth()

标签: php laravel laravel-5 routes


【解决方案1】:

新手错误 - 我有一条带有 customer/{id} 的路线,所以我将新路线改为 open/customer/application。

但是对于任何想知道如何在身份验证范围之外创建路由的人?

在 RouteServiceProvider.php 中,我为“公共”路由创建了一个映射,以使我能够创建一个包含所有路由的新文件:

protected function mapPublicRoutes()
{
    Route::group([
        'namespace' => $this->namespace,
    ], function ($router) {
        require base_path('routes/public.php');
    });
}

在 routes/public.php 我添加了以下内容:

Route::get('open/customer/application', function () {
    return view('customerview.customer-application');
});

路由::auth();最后仍然在我的 web.php 文件中,没有任何问题/冲突。

我希望我的错误能够教育其他人在打扰 Stackexchage 社区之前检查他们的路由文件:')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多