Search code examples
laravelsubdomaincpanelweb-hostinggodaddy-api

I want to host my website admin panel to be served by subdomain


I've cPanel Linux hosting in Godaddy for my website. I just want to host a website for its subdomain as well.

For instance, my website is like "www.domain.com". I've used Laravel framework for my website. I've created some admin panels for my website for this I've created a subdomain like "www.admin.domain.com". I want all my admin routes to be served by this subdomain. Anyone can guide me to achieve this. I appreciate your interest in this.


Solution

  • Just separate the routes of admin and main website. Then group them like this:

    Check here for more details.

    Route::group(array('domain' => 'domain.com'), function() {
        /* routes here */
        Route::get('/link', 'Controller@something');
    });
    
    Route::group(array('domain' => 'admin.domain.com'), function() {
        /* routes here */
        Route::get('/link', 'Controller@something');
    });
    

    There is another way of doing it:

    Route::macro("domain", function(array $domains, \Closure $definition) {
        foreach ($domains as $domain) {
            Route::group(['domain' => $domain], $definition);
        }
    });
    Route::domain(['foo.bar.dev', 'foo.bar'], function($route) {
        // Do stuff
    });