lundi 28 mai 2018

How to set a route parameter default value from request url in laravel

I have this routing settings:

Route::prefix('admin/{storeId}')->group(function ($storeId) {
  Route::get('/', 'DashboardController@index');
  Route::get('/products', 'ProductsController@index');
  Route::get('/orders', 'OrdersController@index');
});

where storeId is a required parameter.

I want storeId to be set automatically from the request URL if provided.

so, if the user requested 'admin/20/products'

then storeId will automatically have the value 20.

maybe something like this.

Route::prefix('admin/{storeId}')->group(function ($storeId) {
  Route::get('/', 'DashboardController@index');
  Route::get('/products', 'ProductsController@index');
  Route::get('/orders', 'OrdersController@index');
})->defaults('storeId', $request->storeId);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire