Eggnog654
Eggnog654

Reputation: 115

How to use Laravel 5.3 subdomain routing?

I have a webpage accessible by localhost/example with a homepage with a company sign up area. Upon submitting that form, the page should redirect to localhost/register.example but I'm getting an error instead.

URL: register.example (the localhost is missing?)
*This site can’t be reached. register.example's server DNS address could not be found.*

web.php Route file

Route::get('/', 'HomepageController@homepage');

Route::group( ['domain' => 'register.example'], function () {
    Route::get('/', [
        'uses' => 'AccountController@register',
        'as' => 'companyregister'
    ]);
});

I have also changed my config/session.php's line to

'domain' => env('SESSION_DOMAIN', 'example'),

I've been looking everywhere but Laracasts' lesson on this one is not available for free. I'm using XAMPP.

Upvotes: 0

Views: 806

Answers (1)

Oniya Daniel
Oniya Daniel

Reputation: 399

If your home page is at localhost/example that means the /example directory is where all your laravel files are kept.
When you are using xamp and the likes, creating sub-domains is another ball game (could be very tricky sometimes).

To give you an illustration, assume you have a domain already: http://example.com
Its sub-domain will be http://register.example.com

So, in your own case (xamp), your domain is http://localhost,
Its sub-domain will be http://register.localhost
(Sadly, I don't know how to set it up in the local environment)

What you are trying to do is Sending post data from your main domain to its sub-domain, which I believe should be handled with an api call.

So I'll advice you to try working with simple routing before going for the sub-domain thingy. Try redirecting your homepage to http://localhost/example/register instead.

Route::get('/', 'HomepageController@homepage');
Route::get('/register', [
    'uses' => 'AccountController@register',
    'as' => 'companyregister'
]);

Upvotes: 1

Related Questions