samedi 30 mars 2019

Laravel, same path on a different subdomain uses wrong controller

Question

How can I set up Laravel routing so that:

  • navigating to mysite.com/login uses the LoginController
  • navigating to somecompany.mysite.com/login uses the TenantLoginController

What I'm doing

I'd have a Laravel 5.7 app that has a typical login page at say, mystite.com/login

I'd like to set up a subdomain for this app like somecompany.mysite.com that will have it's own authentication.

I'd like the somecompany users to log in at somecompany.mysite.com/login


What I've tried

The route definition for the main site login

Route::group(['namespace' => 'App\Http\Controllers\Auth', 'middleware' => ['web']], function () {
    Route::get('login',   'LoginController@showLoginForm')->name('login');
});

The rout definition for the subsomain login

Route::domain('somecompany.mysite.com')->group(function ($router) {
    $router->group(['namespace' => 'App\Http\Controllers\Tenant\Auth', 'middleware' => ['web']], function($router) {
        $router->get('login',   'TenantLoginController@showLoginForm')->name('somecompany.login');
    });
});


What Happened

I can navigate to somecompany.mysite.com/login and the URL bar says somecompany.mysite.com/login but when I do, the request is actually routed to the 'LoginController@showLoginForm' controller not the expected 'TenantLoginController@showLoginForm' and the typical login form is desplayed, not the subdomain's login form.

If I change the path to $router->get('tenant-login' and navigate to somecompany.mysite.com/tenant-login the subdomain login form is shown, and somecompany.mysite.com/login shows the main login form.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OxOqLz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire