Is there anyway to change base url in laravel from controller?
I have two modules in my website one is normal browsing
and another is subscription browsing
. What i want is , when a user comes to my website first, they get to choose what they want to browse. For example if they want to do normal browsing, then i want to redirect to normal browsing and the url should be www.example.com/normal
and i want to make this base url. so what ever link he click there after will be like www.example.com/normal/somelink
. Simillarly for subscription it will be like www.example.com/subscription/somelink
.
If it is possible how can check in the route that he is in subscription browsing/ normal browsing ?
As of now i am adding prefix in the route
. But sometime some url such as login
,user/profile
etc are becoming exception.
So how can i do so, if it possible. Any advice. ty.
My route as of now
/**
* NORMAL BROWSING
*/
Route::group(['middleware' => ['web', 'activity'],'namespace' => 'Frontend'], function () {
Route::prefix('normal')->group(function () {
.......
.......
});
});
/**
* SUBSCRIPTION BROWSING
*/
Route::group(['middleware' => ['web', 'activity'],'namespace' => 'Frontend'],function(){
Route::prefix('subscription')->group(function () {
........
........
});
});
答案 0 :(得分:0)
Little change to your code shall make it work. Assuming auth and web are middlewares
Route::group(['prefix' => 'normal', 'middleware' => ['auth', 'web'], 'namespace' => 'Frontend'], function()
{
Route::get('/', function() {} );
Route::get('/page2', function() {} );
});
This should give take your application home page to website.com/normal and page 2 should be website.com/normal/page2
You can mention other routes outside of the group.
If you want to check if a user is a normal user or a subscription user. you can create a new middleware and use that middleware in the route.
I see that you have already made two middlewares web and activity. Why are you using both the middlewares on a single group route?