inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.06k stars 232 forks source link

Not Supporting Central Domain Routes Correctly #676

Open usmanibrahim74 opened 21 hours ago

usmanibrahim74 commented 21 hours ago

I have Laravel 11 setup with inertia, vue and Multitenant setup using TenancyForLaravel Package. Here is routing code for multitenant setup. Its working fine except for the routes the are limited to central domain only.

->withRouting(
    using: function () {
        $centralDomains = config('tenancy.central_domains');
        foreach ($centralDomains as $domain) {
            Route::middleware('web')->domain($domain)->group(base_path('routes/web.php'));
            Route::middleware('api')->prefix('api')->domain($domain)->group(base_path('routes/api.php'));
        }
        Route::middleware("web")->group(base_path('routes/tenant.php'));
    },
    commands: __DIR__ . '/../routes/console.php',
    health: '/up',
)

here are example routes

Route::prefix('roles')->group(function () {
    Route::get('/', [RolesController::class, 'index'])->name('roles.index');
    Route::get('/table', [RolesController::class, 'table'])->name('roles.table');
    Route::get('/options', [RolesController::class, 'options'])->name('roles.options');
    Route::get('/create', [RolesController::class, 'create'])->name('roles.create');
    Route::post('/', [RolesController::class, 'store'])->name('roles.store');
    Route::get('/{role}/edit', [RolesController::class, 'edit'])->name('roles.edit');
    Route::delete('/{role}', [RolesController::class, 'destroy'])->name('roles.destroy');
});

Route::prefix('tenants')->group(function () {
    Route::get('/', [TenantController::class, 'index'])->name('tenants.index');
    Route::get('/table', [TenantController::class, 'table'])->name('tenants.table');
    Route::get('/create', [TenantController::class, 'create'])->name('tenants.create');
    Route::post('/', [TenantController::class, 'store'])->name('tenants.store');
    Route::get('/{tenant}/edit', [TenantController::class, 'edit'])->name('tenants.edit');
    Route::get('/{tenant}/refresh', [TenantController::class, 'refresh'])->name('tenants.refresh');

    Route::get('/{id}/modules', [TenantController::class, 'modules']);
    Route::post('/{id}/modules', [TenantController::class, 'assign']);
});

Route::prefix('/feedbacks')->group(function () {
    Route::get('/', [FeedbackController::class, 'index'])->name('feedbacks.index');
    Route::get('/table', [FeedbackController::class, 'table'])->name('feedbacks.table');
});

The Roles routes are common in both sides. but tenants and feedbacks routes are only central domain routes. Problem is for the central domain routes only the last domain in the list of central domains in config/tenancy.php work if accessed but if I access through prior domain, links shows last domain in the list instead of the domain through I access. I have a work around to set a central domain in .env file and place it in the list at last. I just want to highlight the issue.

RobertBoes commented 20 hours ago

Don't think this has anything to do with Inertia? Inertia is just a connecting glue between frontend and backend. Routing would still be registered by the backend (Laravel), Inertia doesn't interfere there in any way. The only thing that wouldn't be possible is navigating between domains through Inertia requests (but navigating between different domains likely wouldn't really work anyway, as sessions wouldn't be shared between different domains)