jordans
jordans

Reputation: 48

How to access prefix parameters in closures laravel

I'm trying to access a variable in my routes that is defined in a route prefix.


Route::group( array('prefix' => '{airline_id}','before' => 'airline'), function($airline_id){

Route::get('/edit', function(){

   // Access $airline_id here...

}

});

But it just throws an error saying "Missing argument 1 for {closure}()"...

Is there any way to do this or am I stuck making a bunch of routes..

Upvotes: 0

Views: 1907

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

You cannot use group route this way on Laravel, you're supposed to preset the prefix:

Route::group( array('prefix' => 'swissair','before' => 'airline'), function($airline_id){

    Route::get('/edit', function(){

       // Access $airline_id here...

    }

});

But Jason Lewis Enhanced Router can do it for you:

Route::group(array('prefix' => '{locale}'), function()
{
    Route::get('about', function($locale)
    {

    });

    Route::get('/', function($locale)
    {
        return 'Homepage';
    });
})->where('locale', '(en|fr)');

Upvotes: 3

Related Questions