简体   繁体   中英

Laravel subdomain routing issue

I am having three subdomains for each language in my Laravel application (ET, EN, LV, LT, so my domain would be like et.app.foo.com etc. I have created a route group for subdomains and regular domain. Now there are different user types which use grouping as well with prefix and name. My login page works fine, but all other routes stopped working. I tried to read every possible solution but could not figure it out.

Here is my web.php

$appRoutes = function () {
    require base_path() . '/routes/publicRoutes.php';
    require base_path() . '/routes/physicianRoutes.php';
    require base_path() . '/routes/adminRoutes.php';
    require base_path() . '/routes/generalRoutes.php';
    require base_path() . '/routes/formRoutes.php';
};

/**
 * Group main domain routes
 */
Route::group(
    [
        'domain' => 'app.foo.com'
    ], $appRoutes);

/**
 * Group sub domain routes
 */
Route::group(
    [
        'domain' => '{subdomain}.app.foo.com',
        'as'     => '{subdomain}.'
    ], $appRoutes);

Now here is a part of my admin routes:

Route::group(
        [
            'prefix'     => 'admin',
            'as'         => 'admin.',
            'middleware' => ['auth', 'admin']
        ], function () {

        //when admin land on /home
        Route::get("/home",
            array('as'   => 'dashboard',
                  'uses' => 'Dashboard\HomeController@admin')
        );

And I am getting this error in my sub domain routes and main domain routes:

Missing required parameters for [Route: {subdomain}.admin.dashboard] [URI: admin/home]. (View: 

In my navigation I am calling the route() function. How can I change this so the subdomains will works?

EDIT

When I enter the url manually to the address bar, it works. but when I hover over my hrefs then it doesn't show to subdomain address, but my main domain

EDIT2

I created a custom helper for routing

        function subdomain_route($route)
    {
        if (Config::get('app.subdomain') != null):
            return route($route, ['subdomain' => \Config::get('app.subdomain')]);
        else:
            return route($route);

        endif;
    }

Now I can see that the parameter for the route is subdomain => en but it is still redirecting me to main domain. How can I fix that?

Try placing your sub-domain routes before your main domain routes in the web.php

I had a similar issue which I fixed by placing the Route::domain (or Route::group(['domain' => 'app.foo.com'], $appRoutes) in your case) at the top of the web.php file.

$appRoutes = function () {
    require base_path() . '/routes/publicRoutes.php';
    require base_path() . '/routes/physicianRoutes.php';
    require base_path() . '/routes/adminRoutes.php';
    require base_path() . '/routes/generalRoutes.php';
    require base_path() . '/routes/formRoutes.php';
};

/**
 * Group sub domain routes
 */
Route::group([
        'domain' => '{subdomain}.app.foo.com',
        'as'     => '{subdomain}.'
    ], $appRoutes);

/**
 * Group main domain routes
 */
Route::group(['domain' => 'app.foo.com'], $appRoutes);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM