Search code examples
laravelcontrollers

How to omit nested controller names of routes in Laravel 4?


I have achieved the following route structure using nested controllers

root/areas/eventID/titles/titlesID/sections/sectionsID

Where resourceID is a slug of the preceding controller and areas, titles, and sections are controllers.

I want my URL structure to be root/eventID/titlesID/sectionsID, but I'm not sure how I'd achieve this in my routes.php file since I need to specify the named route. So far, I have set out nested controllers like this:

Route::resource('areas','AreasController');
Route::resource('areas.titles','TitlesController');
Route::resource('areas.titles.sections','SectionsController');

Any ideas?


Solution

  • You can create a route with parameters.

    Route::resource('{eventID}/{titlesID}/{sectionsID}', 'MyController');
    

    Then in your MyController you will have something like this:

    <?php
    
    class AuthController extends BaseController {
    
        public function get()
        {
            // Your code...
        }