Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Backpack with Tenancy for Laravel #329

Open
tabacitu opened this issue Mar 20, 2022 · 2 comments
Open

How to use Backpack with Tenancy for Laravel #329

tabacitu opened this issue Mar 20, 2022 · 2 comments

Comments

@tabacitu
Copy link
Member

Someone just reported that they couldn't get Tenancy for Laravel working with Backpack. Which is weird... I heard some people had it working in the past.

We should probably investigate this. And if it's not easy to do, we should probably create a tutorial / howto / something, to make it easier for devs. It's a pretty popular package.

@adriallongarriu
Copy link

One time use both packages and don't remember to have problems.

I think if needed will be good to have a section in the documentation "Integrating with other packages" like https://tenancyforlaravel.com/docs/v3/integrating not only for Tenancy for Laravel but for other packages.
I once used nwidart/laravel-modules and i had to investigate how to save the backpack related views gruped for modules insted of the genral folder resources\views\vendor\backpack to save views in the module folder for example modules\Core\Resources\views\fields. I investigate how was backpack choosing base views or overrided vies using crud.view_namespaces.

Finally end up creating a trait and call a function on each module ServiceProvider. The funcition is similar to backpack pro
I put the function here because I think it can be helpful for other users.

public function initializeBackpack()
    {
        // tell Backpack to automatically check the FIELDS directory in this package
        app()->config['backpack.crud.view_namespaces.fields'] = (function () {
            $fieldNamespaces = config('backpack.crud.view_namespaces.fields');
            $fieldNamespaces[] = $this->moduleNameLower . '::fields';

            return $fieldNamespaces;
        })();

        // tell Backpack to automatically check the COLUMNS directory in this package
        app()->config['backpack.crud.view_namespaces.columns'] = (function () {
            $fieldNamespaces = config('backpack.crud.view_namespaces.columns');
            $fieldNamespaces[] = $this->moduleNameLower . '::columns';

            return $fieldNamespaces;
        })();

        // tell Backpack to automatically check the BUTTONS directory in this package
        app()->config['backpack.crud.view_namespaces.buttons'] = (function () {
            $fieldNamespaces = config('backpack.crud.view_namespaces.buttons');
            $fieldNamespaces[] = $this->moduleNameLower . '::buttons';

            return $fieldNamespaces;
        })();

        // tell Backpack to automatically check the FILTERS directory in this package
        app()->config['backpack.crud.view_namespaces.filters'] = (function () {
            $fieldNamespaces = config('backpack.crud.view_namespaces.filters');
            $fieldNamespaces[] = $this->moduleNameLower . '::filters';

            return $fieldNamespaces;
        })();

        // tell Backpack to automatically check the WIDGETS directory in this package
        app()->config['backpack.base.component_view_namespaces.widgets'] = (function () {
            $fieldNamespaces = config('backpack.base.component_view_namespaces.widgets');
            $fieldNamespaces[] = $this->moduleNameLower . '::widgets';

            return $fieldNamespaces;
        })();
    }

@simke92
Copy link

simke92 commented Dec 27, 2023

I've been struggling for the past few days to implement multi-tenancy using Laravel, Backpack v6, and multiple databases. I've attempted both subdomain and path-based tenant identification, but I haven't been able to make it work seamlessly.

Here's my setup: I started with a fresh Laravel project with Breeze, and everything was functioning correctly. However, when I added Backpack CRUD to the project, I encountered several issues:

Login Problems: I can only log in to the application using a user from the central database, and this user has access to both the central and tenant routes. Unfortunately, the tenant database doesn't have the same users, and attempting to log in with tenant-specific credentials doesn't work as expected.

Access to CRUD Routes: Even after successfully logging in, I'm unable to access most of the CRUD routes provided by Backpack. The only route that seems to work is the blank dashboard. When I try to load any view from a CRUD controller, I encounter a 419 PAGE EXPIRED and redirected to login page again.

I'm seeking advice and guidance on how to effectively implement multi-tenancy with Backpack v6 in my Laravel project. Any insights, suggestions, or solutions from the community would be greatly appreciated.

Thank you in advance for your assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants