How To Get Subdomain Inside RouteServiceProvider Map() Method While Phpunit Testing?

- 1 answer

Is there a way to get the subdomain while running phpunit test in Laravel?

And more specific in this method:


 * Define the routes for the application.
 * @return void
public function map()

    // inside here get subdomain while running a phpunit test??

So if I make some dummy test like this:

/** @test */
public function user_can_see_welcome_page()
    $response = $this->call('GET', '');


I want to get the subdomain inside that map() method of RouteServiceProvider



In order to change the domain you can add it to the phpunit.xml to set it globally:

    <env name="APP_URL" value=""/>

But discussing your problem in the comments, this is the actual solution to your problem:

Multiple route files:

You could split each subdomain in its own map method and route file and register them in your RouteServiceProvider.

for each subdomain:

protected function mapSubDomainRoutes()
        'middleware' => 'web',
        'domain' => '',
        'namespace' => $this->namespace,
    ], function () {
        require base_path('routes/subdomain.domain.php');

Single route file:

Or if you have everything inside one route file you can wrap the routes inside a group:

Route::group(['domain' => ['']], function () {
    // domain specific routes