Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LdCoding's avatar

Laravel Multi-tenancy : Missing required parameter for [Route: user.index] [URI: {tenant}/admin/user] [Missing parameter: tenant].

After installing and configuring stancl/tenancy package on an existing project, I chose to go with Path Identification to know which tenants should be set, and tried adding routes like so :

routes\tenant.php :

Route::group([
    'prefix' => '/{tenant}',
    'middleware' => [
        InitializeTenancyByPath::class,
    ],
], function () {
    Route::get('/', function () { // this route works fine
        return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
    });

Route::group([
        'namespace'  => 'App\Http\Controllers\Admin',
        'prefix'     => 'admin',
        'middleware' => ['auth'],
    ], function () { // these routes throw the same error as the one shown below
        Route::resource('user', 'UserController');
        Route::resource('role', 'RoleController');
        Route::resource('permission', 'PermissionController');
        Route::get('edit-account-info', 'UserController@accountInfo')->name('admin.account.info');
        Route::post('edit-account-info', 'UserController@accountInfoStore')->name('admin.account.info.store');
        Route::post('change-password', 'UserController@changePasswordStore')->name('admin.account.password.store');
    });
});

However, when accessing this route /foo/admin/user, the following error occured:

Missing required parameter for [Route: user.index] [URI: {tenant}/admin/user] [Missing parameter: tenant]. (View: /path/to/project-placeholder/resources/views/layouts/navigation.blade.php)

img

I'm not sure what is happening here. It could be that my auth middleware has no idea about this 'tenant' parameter.

Any Ideas ?

0 likes
5 replies
tykus's avatar

Where are you actually using the route helper method? Are you remembering to pass the {tenant} parameter there?

route('users.index', 'foo')

or better, because it expresses the intent of the parameter and will be consistent across the various usage scenarios:

route('users.index', ['tenant' => 'foo'])
route('users.show', ['tenant' => 'foo', 'user' => 123])
LdCoding's avatar

@tykus this is what the problem is, the auth middleware tried to redirect to login if the user is not connected, but no tenant parameters are passed. I am currently thinking of a way to automatically merge the tenant parameter whenever the path being requested is a tenant. Maybe overriding the route(), view(), redirect(), etc... helper methods or creating alternative ones for this usecase is the way to go, what do you think ?

Example :

  • if domain.com/foo/admin/user : merge tenant param to rest of params route($route, array_merge($parameters, ['tenant' => tenant('id')]), $absolute);
  • else if domain.com/admin/user : do nothing route($route, $parameters, $absolute);
LdCoding's avatar

The second issue I think is with conflicting route names. If I have a route in web.php :

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');

And another one in tenant.php :

Route::get('/{tenant}/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');

Then the one in tenant.php will always "win" according the the documentation. meaning I have to have different names aswell ie : ->name('tenant.dashboard').

which means I would need to refactor all cases of route('dashboard') to actually send to route('tenant.dashboard') instead. Is there a way I could deal with this implicitly aswell ? so that the route function would understand to add the tenant. prefix given some sound condition (maybe if tenant('id') is set or if previous route was a tenant route... not sure )

tykus's avatar

@full do you rely on the route URI segment to determine if there is a tenant;or is there something also in the Session

ivanwddit's avatar

I've an issue like this trying to implement filament on a multitenancy by path still working project. Has someone any suggestions for making panelProviders working?

Please or to participate in this conversation.