2016-10-31 96 views
0

我想路由組類似下面的內推廣了一些常見的途徑:Laravel訪問可選路線組前綴

# Administrative routes 

Route::group(array('prefix' => '{word}'), function($parameter) { 

    // $table = $parameter->...? 

    Route::post('restore', ['as'=>$table.'.restore', 'uses'=>ucfirst($table).'[email protected]']); 
    Route::get('{id}/suspend', ['as'=>$table.'.suspend', 'uses'=>ucfirst($table).'[email protected]']); 
    Route::get('{id}/activate', ['as'=>$table.'.activate', 'uses'=>ucfirst($table).'[email protected]']); 
}); 

但我不知道如何使用通過回調函數傳遞的參數$。

如何從參數中獲取路由前綴字符串?

回答

0

哦......那它應該是簡單的:

# Administrative routes 

Route::group(array('prefix' => '{word}'), function($parameter) { 

    $table = Request::segment(1); 
    $controller = ucfirst($table).'Controller'; 

    Route::post('restore', ['as'=>$table.'.restore', 'uses'=>$controller.'@restore']); 
    Route::get('{id}/suspend', ['as'=>$table.'.suspend', 'uses'=>$controller.'@suspend']); 
    Route::get('{id}/activate', ['as'=>$table.'.activate', 'uses'=>$controller.'@activate']); 
}); 

如果你可以從函數參數$把它拿來隨意分享如何。