Answer the question
In order to leave comments, you need to log in
How to route multiple domains in one Laravel?
Laravel has routing, and it is possible to group routes depending on the domain.
There were no problems with grouping routes by subdomains, but it didn’t work out to do something like this.
Route::group(['domain' => '{domain}'], function () {});
Answer the question
In order to leave comments, you need to log in
Maybe if you really need to. Not recommended, of course, but doable.
Here are the functions. Personally, I get the domain in the RouteServiceProvider, where it is scattered over the files as needed.
But you can implement some kind of middleware that will shove the domain somewhere (so as not to pull the function every time), or get the file in the same route Provider for the domain.
if (! function_exists('subdomain')) {
/**
* Returns subdomain.
*
* @return string
*/
function subdomain()
{
$exploded = explode('.', Request::getHost());
return count($exploded) == 3 ? $exploded[0] : null;
}
}
if (! function_exists('domain')) {
/**
* Returns domain.
*
* @return string
*/
function domain()
{
$exploded = explode('.', Request::getHost());
return join('.', array_slice($exploded, -2, 2, true));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question