Sha*_*yal 5 php routing laravel lumen lumen-5.2
我在laravel / lumen中声明了一个路由组,如下所示:
$app->group(['middleware' => 'auth'], function () use ($app) {
$app->get('/details', 'UserController@details');
});
Run Code Online (Sandbox Code Playgroud)
路由文件web.php的所有内容如下:
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app = app();
$router->get('/', function () use ($router) {
return $router->app->version();
});
$app->group(['middleware' => 'auth'], function () use ($app) {
$app->get('/details', 'UserController@details');
});
Run Code Online (Sandbox Code Playgroud)
我得到一个错误 Call to undefined method Laravel\Lumen\Application::group()
如何使用中间件添加路由组?
小智 5
实际上,正如@Aine在Lumen 5.5+中所说的,您应该更改:
LumenPassport::routes($this->app);
至
LumenPassport::routes($this->app->router);
申请不再有group()
方法。
谢谢
找到了问题的解决方案:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->group(['prefix' => 'api'], function () use ($router) {
$router->get('/', function () use ($router) {
return "API";
});
$router->post('/signin','UserController@signin');
$router->post('/signup','UserController@signup');
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->get('/details', 'UserController@details');
});
});
Run Code Online (Sandbox Code Playgroud)
为了对路由进行分组,我们必须使用:
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->get('/details', 'UserController@details');
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6807 次 |
最近记录: |