Using Namespace in Route Group

5269 views

Description:

Cleaner way to use namespace in a route group in Laravel version 4.1

Credits to: Thomas Clarkson & Sefa Karagöz

Resource: https://github.com/sseffa/sf_cms/blob/master/app/routes.php

// version 4.0
Route::group(array('prefix' => 'members', 'before' => array('auth')), function()
{
    Route::get('snippets/{slug}', array('uses' => 'LaraSnipp\Controllers\Member\SnippetController@getShow',
        'as' => 'member.snippet.getShow'));
    Route::get('snippets/{slug}/edit', array('uses' => 'LaraSnipp\Controllers\Member\SnippetController@getEdit',
        'as' => 'member.snippet.getEdit'));
    Route::post('snippets/{slug}/update', array('uses' => 'LaraSnipp\Controllers\Member\SnippetController@postUpdate',
        'as' => 'member.snippet.postUpdate'));
});

// version 4.1
Route::group(array('prefix' => 'members', 'namespace' => 'LaraSnipp\Controllers\Member', 'before' => array('auth')), function()
{
    Route::get('snippets/{slug}', array('uses' => 'SnippetController@getShow',
        'as' => 'member.snippet.getShow'));
    Route::get('snippets/{slug}/edit', array('uses' => 'SnippetController@getEdit',
        'as' => 'member.snippet.getEdit'));
    Route::post('snippets/{slug}/update', array('uses' => 'SnippetController@postUpdate',
        'as' => 'member.snippet.postUpdate'));
});

Submitted 10 months ago.
Updated 5 minutes ago.

comments powered by Disqus

Want to help with the site? We accept pull requests! Find us on Github