laracastsluvr
1 month ago

L5.8 - Dynamic Prefix to include an id

Posted 1 month ago by laracastsluvr

Hello friends,

Got another one! A question that is ;)

Is there an efficient way to have a view (a dashboard for example) display certain settings based on a route prefix with a property ID?

For example:

domain.tld/store/{store_id}/messages/{message_id}

The abobe example should fetch messages of a store with store_id = x. Also after all Authentication and Authorization is passed!

My first thought was after the user logs in, they would be presented with a selector page to pick which "store/entity" they would like to proceed in working with.

Hello, please select the store you would like to access

Store 1 link -> domain.tld/store/1001/
Store 2 link -> domain.tld/store/1010/
etc.
...
Route::group(['prefix' => 'store/{store_id}'], function() {
    Route::get('/', function() {
        ...
    })->name('dashboard');

    Route::get('settings', function() {
        ...
    })->name('settings');

    Route::get('messages/{id}', function() {
        ...
    })->name('messages');
});
...

Or should I scrap this idea and go with a session key that stores the selected store_id from the "selector" entry page then access it every time on the app's controllers?

Any advice or another way possible?

Please sign in or create an account to participate in this conversation.