2

I am creating an ERP system with multi-tenant with different db and has sub-domain for tenants. I am using the stancl\tenancy for the multi tenant package.

I have a main domain for creating and adding companies

Normally, when I load users in my tenant's sub-domains (eg "foo.maindomain.com") it is only showing the users table in the tenant's db. But with the Backpack dashboard in permission manager it is showing the users in the main database instead of the user in the tenant's own database.

How can I solve this problem?

halfer
  • 19,824
  • 17
  • 99
  • 186
P7rck
  • 116
  • 1
  • 5

1 Answers1

1

The docs for that tenancy package show that they use a various middlewares that set the tenant for the application. Based on your question, Ill assume you're using the Subdomain identification middleware in your app.

The issue is most likely that your Backpack permissions routes are not using this middleware.

If we look at Backpack's docs, they say this about the permissions routes:

If you need to modify how this works in a project:

create a routes/backpack/permissionmanager.php file; the package will see that, and load your routes file, instead of the one in the package;

To fix the issue, create a file at allin.com/routes/backpack/permissionmanager.php copy the contents from vendor/backpack/permissionmanager/src/routes/backpack/permissionmanager.php, paste that in the new file and add the middleware needed for the tenancy app, which should look something like:

Route::group([
    'namespace'  => 'Backpack\PermissionManager\app\Http\Controllers',
    'prefix'     => config('backpack.base.route_prefix', 'admin'),
    'middleware' => ['web', InitializeTenancyBySubdomain::class, backpack_middleware()],
], function () {
    Route::crud('permission', 'PermissionCrudController');
    Route::crud('role', 'RoleCrudController');
    Route::crud('user', 'UserCrudController');
});
Wesley Smith
  • 19,401
  • 22
  • 85
  • 133