路线集团流明错误呼叫到
问题描述:
我已经宣布的路线组laravel /流明像这样未定义的方法Laravel \流明\应用::组():路线集团流明错误呼叫到
$app->group(['middleware' => 'auth'], function() use ($app) {
$app->get('/details', '[email protected]');
});
路由文件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', '[email protected]');
});
上拨打电话,以http://THE_URL/
我得到一个错误Call to undefined method Laravel\Lumen\Application::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','[email protected]');
$router->post('/signup','[email protected]');
$router->group(['middleware' => 'auth'], function() use ($router) {
$router->get('/details', '[email protected]');
});
});
为了组击溃我们必须使用:
$router->group(['middleware' => 'auth'], function() use ($router) {
$router->get('/details', '[email protected]');
});
+0
我听不懂。如何解决这个问题? –
+0
@MarceloRodovalho你面临什么问题? –
你检查吗? https://lumen.laravel.com/docs/5.2/routing#route-groups,虽然它看起来与你所做的不一样。 –
等待!你必须添加'$ app = app(); $路由器 - >获取( '/',()的函数使用($路由器){ 回报$路由器 - > APP->版本(); });'? –
@OmisakinOluwatobi是的,我检查了网址,你在第二个评论中提到的部分是在流明中定义的默认路由,我也添加了'$ app = app();',因为它没有被发现 –