Hi @murtaza1904
Maybe I need more info about the project, for example how the regions are stored or linked with the user, but a way could be to set it in the session or authentication guard (after login) and then retrieve it from there when needed. So, in your login controller, you could do something like:
// After validation and checking credentials
auth()->login($user);
session(['region_prefix' => $user->region]);
return redirect()->route('dashboard');
And to create URLs, you could make a helper function like this:
function region_route($name, $parameters = [], $absolute = true)
{
return app('url')->route($name, array_merge(['reg' => session('region_prefix')], $parameters), $absolute);
}
Then in your views, instead of route('dashboard'), you can use region_route('dashboard') and it will append the region automatically without having to pass it manually. The group routes should be like this:
Route::prefix('{reg}')->group(function ()
{
// all the routes will come here
});
This should work with your current {reg} prefix, but remember to replace all hard-coded region prefixes {reg} with session('region_prefix') to ensure user can change the region from dashboard.
(no tested)