【问题标题】:Auth or auth-api middleware in api routes in laravellaravel 中 api 路由中的 Auth 或 auth-api 中间件
【发布时间】:2018-10-09 19:24:22
【问题描述】:

对于我目前正在使用的 apis 身份验证:

Route::group([
  'middleware' => 'auth:api'
], function() {
    Route::post('logout', 'AuthController@logout');
    Route::get('user', 'AuthController@user');
});

如果我想为基于会话的登录使用相同的方法,我需要在 web.php 文件中创建相同的路由,还是可以在 AuthController 构造函数中使用类似这样或这样的方式设置中间件?

在这个answer 'auth:api' 中意味着 auth 正在检查 api,所以我需要在那里传递任何东西来检查像 'auth:api,web' 之类的会话吗?

【问题讨论】:

    标签: php laravel middleware


    【解决方案1】:

    在 web.php 中创建相同的路由只需省略中间件,因为 web 中间件是自动应用的。 api.php 也是如此,auth:api 是那里的默认中间件。

    【讨论】:

      猜你喜欢
      • 2017-09-01
      • 2021-11-21
      • 2018-09-22
      • 1970-01-01
      • 2021-11-23
      • 2017-07-04
      • 2018-11-07
      • 2019-06-09
      • 1970-01-01
      相关资源
      最近更新 更多