Ad
How To Get Subdomain Inside RouteServiceProvider Map() Method While Phpunit Testing?
Is there a way to get the subdomain while running phpunit test in Laravel?
And more specific in this method:
app/Providers/RouteServiceProvider.php
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
// 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', 'https://subdomain.domain.com');
$response->assertStatus(200);
}
I want to get the subdomain
inside that map() method of RouteServiceProvider
Ad
Answer
In order to change the domain you can add it to the phpunit.xml
to set it globally:
<php>
<env name="APP_URL" value="https://subdomain.domain.com"/>
</php>
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()
{
Route::group([
'middleware' => 'web',
'domain' => 'subdomain.domain.com',
'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' => ['subdomain.domain.com']], function () {
// domain specific routes
});
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad