Search code examples
phplaravellaravel-5laravel-5.3

Laravel registration and login pages on a subdomain


I am creating a website in Laravel 5.3 that has two different entry points for registration, these entry points need to be subdomains.

I've setup the two routes but I am a bit lost how I would setup the Auth::routes() for the two subdomains.

One route will be for users who will register and pay a monthly subscription fee while the other route will not have a subscription fee attached to them.

As a site note: the two registration forms are identical at the moment but one could get a few more fields added than the basic username / password fields (think of name, surname, etc).


Solution

  • There is a sub-domain-feature in the routing component:

    Route groups may also be used to handle sub-domain routing. Sub-domains may be assigned route parameters just like route URIs, allowing you to capture a portion of the sub-domain for usage in your route or controller. The sub-domain may be specified using the domain key on the group attribute array:

    Route::group(['domain' => '{account}.myapp.com'], function () {
        Route::get('user/{id}', function ($account, $id) {
            // your code
        });
    });
    

    https://laravel.com/docs/5.3/routing#route-group-sub-domain-routing