Saturday, March 4, 2017

Sub-domain routing in Laravel

I'm trying to get subdomain routing working for wildcard subdomains in Laravel 5.4. My routes look like this:

Route::group(array('domain' => '{subdomain}.example.com', 'middleware' => 'tenant'), function() {
//routes for any subdomain
});
//routes for example.com

the problem is that the subdomain is being passed to every single route. To solve this issue i added the following to my middleware:

$request->route()->forgetParameter('subdomain');

Now i got the problem that all the routes which i specified in my views are missing the subdomain parameter and i have to write every route like that:



what is the proper way to do subdomain routing in Laravel?



via drunk

Advertisement