Laravel:如何允许路由组公开?

时间:2018-02-21 16:22:07

标签: php laravel authentication jwt

我是Laravel 5.6的新用户,正在尝试使用公共路径 /signup编写API。

对于JWT身份验证,我使用jwt-auth 1.0.0-rc.2

路由/ api.php

// This code WORKS, the route is public
Route::middleware('guest:api')->get('/signup', function(Request $request) {
    return "Sign up"; // This code belongs in the controller
});

// This code DOES NOT WORK, authentification needed
Route::get('signup', 'AuthController@signup')->middleware('guest');

// This code DOES NOT WORK
Route::group([
    'middleware' => 'guest:api'
], function($router) {
    Route::get('signup', 'AuthController@signup');
});

我无法在docs中找到任何有用的内容,但这应该是我添加guest权限的错误方式,因为第一个示例有效。

如何使不工作的代码工作?任何的想法?谢谢!

1 个答案:

答案 0 :(得分:1)

Route::middleware(['guest:api'])->group(function () {
    Route::get('signup', 'AuthController@signup');
    Route::get('mySecondRoute', 'AuthController@mySecondFunction');
});

甚至只是

Route::get('signup', 'AuthController@signup');

任何一组