Patrick Maciel Patrick Maciel - 1 month ago 10
PHP Question

Admin Routes (or Prefix Routes) in Laravel 4

How can I create admin specific routes in Laravel 4 (Restfull Controllers):

/admin/users (get - /admin/users/index)
/admin/users/create (get)
/admin/users/store (post)


I want to know:


  • What Files and where I need create theam

  • How I need create the route


Answer

In Laravel 4 you can now use prefix:

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

    Route::get('/', 'AdminController@home');

    Route::get('posts', 'AdminController@showPosts');

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

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

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

});
Comments