2017-09-21 82 views
2

我已經宣佈的路線組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()

ERROR

如何添加路由組與中間件?

+0

你檢查嗎? https://lumen.laravel.com/docs/5.2/routing#route-groups,雖然它看起來與你所做的不一樣。 –

+0

等待!你必須添加'$ app = app(); $路由器 - >獲取( '/',()的函數使用($路由器){ 回報$路由器 - > APP->版本(); });'? –

+0

@OmisakinOluwatobi是的,我檢查了網址,你在第二個評論中提到的部分是在流明中定義的默認路由,我也添加了'$ app = app();',因爲它沒有被發現 –

回答

-1

找到解決問題的辦法:

<?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你面臨什麼問題? –