Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

From the docs http://laravel.com/docs/routing#route-filters

Route::get('user', array('before' => 'auth|old', function()
{
    return 'You are authenticated and over 200 years old!';
}));

I'm assuming you could do a group the same way, but I it's untested.

Last updated 2 years ago.
0

Thanks, I know about that option. But I have several that need other filtering. That's why I want to nest them and break it down.

Last updated 2 years ago.
0

@MacWorks, you need to add "prefix" to your route group. Here is section of my route file.

Route::group(['prefix' => 'admin', 'namespace' => 'Controllers\Admin'], function()
{
    // /admin/dashboard
    Route::get('dashboard', [
        'as' => 'admin_dashboard', 
        'uses' => 'DashboardController@getIndex'
    ]);

    ...

    // /admin/members
    Route::group(['prefix' => 'members'], function()
    {
        Route::get('/', [
            'as' => 'admin_members', 
            'uses' => 'UsersController@getMemberList'
        ]);
        
        // /admin/members/search
        Route::get('search', [
            'as' => 'admin_member_search', 
            'uses' => 'UsersController@getMemberSearch'
        ]);

        Route::get('{id}/status', [
            'as' => 'admin_member_inactive', 
            'uses' => 'UsersController@getUserInactive'
        ]);

        Route::post('{id}/remove', [
           'before' => 'isGod',
            'as' => 'admin_member_remove', 
            'uses' => 'UsersController@postRemove'
        ]);
        
        Route::get('mailinglist', [
            'as' => 'admin_member_maillist', 
            'uses' => 'UsersController@getMailingList'
        ]);

    });
    
    ...
});
Last updated 2 years ago.
0

Can you filter based on prefixes?

Last updated 2 years ago.
0

Yes you can. Pattern Based Filters

Route::when('admin/*', 'admin', array('post'));
Last updated 2 years ago.
0

You can also nest groups as explained here: http://www.laravel-tricks.com/tricks/route-group-namespacing Hope it helps!

Last updated 2 years ago.
0

I also have this issue.

I have route group inside another route group working.

But if I now need to have another route group that the initial route groups must be within, as I need to apply a filter to all routes. I can't add the filter to the first group as the filter is needed before a prefix is added.

So is there some way around this nesting problem? I don't understand how name space groups will help me fix this, but I am quite new to Laravel.

Update: Ofcourse I found the answer soon after making the post.

My problem was that I was using groups for filters in combination with individual filters. It seems you can't apply 3 levels of nested grouping and then a filter to an individual route.

So my solution was to make all routes in groups for each filter, and have no filters applied to an individual route. This may well be documented, but I missed it.

Last updated 2 years ago.
0

A working example of nested groups with no prefix or namespace

I needed guest filter applied to all 4 routes but csrf only for the post routes.

Route::group(['before' => 'guest'], function()
{
    //only require the guest filter
    Route::get('login', ['as' => 'login.create', 'uses' => 'SessionsController@create']);
    Route::get('register', ['as' => 'register.create', 'uses' => 'RegistrationController@create']);

    //require both guest and csrf filter
    Route::group(['before' => 'csrf'], function()
    {
        Route::post('login', ['as' => 'login.store', 'uses' => 'SessionsController@store']);
        Route::post('register', ['as' => 'register.store', 'uses' => 'RegistrationController@store']);
    });
});
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

MacWorks macworks Joined 6 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.