簡體   English   中英

Laravel組管理員路線

[英]Laravel group admin routes

有沒有一種方法可以對所有以admin/開頭的路由進行干凈的分組? 我嘗試了類似的方法,但是它當然沒有用:

Route::group('admin', function()
{
    Route::get('something', array('uses' => 'mycontroller@index'));
    Route::get('another', array('uses' => 'mycontroller@second'));
    Route::get('foo', array('uses' => 'mycontroller@bar'));
});

對應於以下路線:

admin/something
admin/another
admin/foo

我當然可以直接用admin/所有這些路由的前綴,但是我想知道是否有可能按照我的方式進行

謝謝!

很不幸的是,不行。 路由組的設計並非如此。 這取自Laravel文檔。

路由組使您可以將一組屬性附加到一組路由,從而使代碼保持整潔。

路由組用於將一個或多個過濾器應用於一組路由。 您正在尋找的是捆綁包!

捆綁包介紹!

從外觀上看,捆綁銷售就是您的追求。 在bundles目錄中創建一個名為“ admin”的新bundle,並將其注冊到application / bundles.php文件中,如下所示:

'admin' => array(
    'handles' => 'admin'
)

使用handles鍵可以更改捆綁軟件將響應的URI。 因此,在這種情況下,對admin的任何調用都將通過該捆綁包運行。 然后在新的包中創建一個route.php文件,然后可以使用(:bundle)占位符注冊處理程序。

// Inside your bundles routes.php file.
Route::get('(:bundle)', function()
{
    return 'This is the admin home page.';
});

Route::get('(:bundle)/users', function()
{
    return 'This responds to yoursite.com/admin/users';
});

希望能給您一些想法。

Laravel 4您現在可以使用prefix

Route::group(['prefix' => 'admin'], function() {

    Route::get('something', 'mycontroller@index');

    Route::get('another', function() {
        return 'Another routing';
    });

    Route::get('foo', function() {
        return Response::make('BARRRRR', 200);
    });

    Route::get('bazz', function() {
        return View::make('bazztemplate');
    });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM