Look at config/sessions.php and https://laravel.com/docs/5.2/routing#route-group-sub-domain-routing.
Managing Subdomain
I am working on a ecommerce site from laravel.I want subdomain according to user's.How can it be done ??Any configuration to be made?? Thanks in advance !!!
You can place your routes inside a group with dynamic domain like
Route::group(['domain' => '{whatever}.domain.com'] , function() {
// define your routes here
});
However, first parameter passed to your controller methods will always be the value of whatever.
You can however remove the variable with a middleware, but that also means that you don't have that variable anymore for redirecting to the correct subdomain
public function handle($request, Closure $next)
{
$route->forgetParameter('identifier');
return $next($request);
}
@pmall I think you know something about this right? Maybe you can share your knowledge ;)
I don't remember the syntax exactly but parameters can be forgot.
@bobbybouwmann Yes, you can forget the parameters, i do the same for versioning my api. However, It makes things only complicated. As you have already mentioned route() won't work correctly, you will require a sort of manager to remember the parameter and be the proxy for all those functions which are dependent on the parameter in question.
So, for most , the simplest approach would be to declare it as the first parameter of the controller methods.
I wrote a simple helper function called subRoute which grabs the subdomain from the session. I set the session in a middleware where I remove the variable from the parameters in the request (see code above).
This however makes things also complicated for redirecting and for example the Form helper. I need to create helper functions for all of these functions.
That's what i meant by sort of manager and all those functions which are dependent on the parameter in question
Please or to participate in this conversation.