Laravel Route Groups (Laravel 4)

I just found out that in Laravel you can add groups to your routes. Say for instance that you need to apply an authentication filter inside many routes. Instead of adding that filter through each and every route you can wrap them inside a group.

For example:

/**
  * Unauthenticated routes
**/
Route::group(array('before' => 'guest'), function()
{
    Route::get('/', function()
    {
        // Has guest Filter
    });

    Route::get('user/create', function()
    {
        // Has guest Filter
    });
});

As you can see, Laravel route groups can be useful for grouping authenticated routes and unauthenticated routes with their needed filters.

Resources

Route Groups: http://laravel.com/docs/routing#route-groups

Tyler Souza

Tyler is a very passionate full-stack developer who thrives on a challenge. He specializes in programming (mainly in Python), REST API development, and keeps up with the latest front-end technologies. When not coding, he loves to eat ramen, BBQ, and travel.

You may also like...