Laravel group routing issue

- 1 answer

Ad

Laravel routing issue while using the contrain on parameter with routing without ->where('id', '[0-9]+'); working but I need to add this.

Route::group(['prefix' => '/{id}'], function () { 
    Route::post('/edit', 'User\[email protected]');
})->where('id', '[0-9]+');

Which causes the following error

Call to a member function where() on a non-object

Ad

Answer

Ad

This is the proper way. This way you can define multiple where conditions. Not tested but hope you get the idea.

Route::group([
    'prefix' => '/{id}',
    'where'  => [
      'id' => '[0-9]+'
    ]
  ], 
  function () { 
    Route::post('/edit', 'User\[email protected]');
});
Ad
source: stackoverflow.com
Ad