当前位置: 首页 > 知识库问答 >
问题:

Laravel总是带我到登录页面

潘胤
2023-03-14

我正在使用Laravel 5的身份验证模块为我的应用程序。然而,在我创建了auth函数与PHP工匠make: auth我只能访问两个路径:/登录和 /register无论我如何添加路由在routes.php.所有其他路径重定向我到登录页面。如何使用户在不记录的情况下访问某些路径?谢谢。

路线。php:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::auth();

Route::get('/home', 'HomeController@index');

Route::get('/patient', 'HomeController@registerPatient');

Route::get('test', 'HomeController@index');

Route::group(array('before' =>'auth'), function()
{
    Route::get('about',  array('as' => 'about','uses' => 'HomeController@about'));
}
);

Route::group(array('before' =>'auth'), function()
{
    Route::get('/physician',  array('as' => 'physician','uses' => 'HomeController@registerPhysician'));
}
);

共有1个答案

姬博瀚
2023-03-14

你能分享你的控制器代码吗?我的意思是,在你的控制器结构中有auth中间件吗?

    Route::group(['middleware' => 'web'], function () {
    Route::auth();
    Route::get('/', function () {
            return view('welcome');
          });
    Route::get('/home', 'HomeController@index');
    Route::get('/patient', 'HomeController@registerPatient');
    Route::get('test', 'HomeController@index');
    });

Route::group(array('before' =>'auth'), function()
{
    Route::get('/physician',  array('as' => 'physician','uses' => 'HomeController@registerPhysician'));
Route::get('about',  array('as' => 'about','uses' => 'HomeController@about'));
}
);

不管怎样,检查你的构造方法在主控制器和应用auth中间只对某些方法

 public function __construct()
    {
        $this->middleware('auth', ['except' => [
            'about',
            'index',
        ]]);
    }
}
 类似资料:
  • 我在Laravel框架中的HomeController.php中有一段代码,但是我无法访问它重定向到登录页面的索引/主页。我犯了什么大错?

  • 当(在Spring Security/MVC中)页面访问被拒绝时,由于用户没有足够的权限(尽管他已通过身份验证),我需要通过显示登录页面(而不是显示403拒绝访问页面的标准行为)提供作为另一个用户登录 我可以编写一个,重定向到登录页面。但是,当Spring Security发现有另一个用户登录时,它会做出怎样的反应?当新用户已成功通过身份验证时,我能否以某种方式注销旧用户?

  • 我在laravel中遇到了一个用户登录的问题,我可以正确地登录用户,但是问题是,在用户登录后,他被重定向到login POST方法,而不是home,我已经将

  • 我希望我的这个登录页面加载两次,即第一次用户输入username和password,然后从servlet获得响应,然后它将被重定向到带有“messages”的登录jsp页面。 我有两个按钮用于登录和注销。这个脚本可以像我试过的那样通过使用count变量加载两次吗?任何其他方法也将是首选。 附注:我试过使用和但它们不起作用。 login.jsp:-

  • 记录器文件中的日志- org.springframework.Security.Access.event.loggerlistener-安全授权失败,原因是:org.springframework.Security.Access.accessdeniedexception:访问被拒绝;通过身份验证的主体:org.springframework.security.authentication.ano

  • 我现在一直在努力使用我的登录页面来让组件呈现Loggedin组件。我的前端是Reactjs,后端是NodeJS。我对nodejs、expression和react都是新手。 在loginform组件上,我使用fetch进行了一次post,它将用户名和密码传递给后端的相应endpoint。没问题。在后端,它读取我存储用户(不使用任何数据库)的jsonfile来查找匹配项,如果用户名和密码都匹配,则它