archtechx / tenancy

Automatic multi-tenancy for Laravel. No code changes needed.
https://tenancyforlaravel.com
MIT License
3.65k stars 429 forks source link

Implementing Laravel Voyager for tenants #443

Closed middle21 closed 4 years ago

middle21 commented 4 years ago

Hello.I have a project that uses Laravel Voyager for the administration panel and I would like to add stancl/tenancy for this project. I can successfully create new tenants (all migrations are done correctly, all assets load correctly), and i can login. I'm using hexxie.com for local dev/testing (it points to 127.0.0.1:80 so i can easily add tenants without modifying the hosts file). I 'm using php 7.3.18, Laravel 7.14.1, composer 1.10.7, tcg/voyager 1.4.1 and stancl/tenancy 3.x-dev.

The problem is that when I hit /admin on one of the tenants (foo.hexxie.com/admin) ,I can indeed see the administration panel's dashboard but I can't see the widgets and the menu items in the sidebar.Also if I take a look into laravel-debugbar in the Gates section, i get 32 errors, all looking similar to this:

array:4 [▼ "ability" => "browse" "result" => null "user" => 1 "arguments" => "[0 => Object(TCG\Voyager\Models\User)]" ]

Finally if I go to /admin/posts or /admin/pages (foo.hexxie.com/admin/posts), I get the following error :

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'multitenant.categories' doesn't exist (SQL: select * from categories where parent_id is null order by order asc)

Its trying to get the categories, but from the main database, not from the tenant's database.

**While writing this I realized I have a ViewComposer that gets the categories and returns them to all pages (I use this because I have to list the categories in a partial in the header -- not in the administration panel).If I disable this, when I access foo.hexxie.com/admin/posts it returns the following error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'multitenant.settings' doesn't exist (SQL: select * from settings order by order asc) (View: /opt/lampp/htdocs/multitenant/resources/views/partials/header.blade.php)

So it seems that the settings function (its primarily used in views - ex: {{ settings(site.title) }} ) can't select the tenant's database and its using the main database.

EDIT: So it seems the SQL errors were generated by the fact the I was using custom 404 blade views.I changed them back to their defaults and I added an extra check in the View Composer ( (if tenancy()->tenant == null) return $view; -- if its not null, it will execute as usual). Now it seems that the Voyager routes are not registered (/admin/products returns 404).

All help would mean a lot.Thanks and have a great day!

EDIT2: There isn't a problem with the package, but with the way the Voyager routes are registered ( In vendor/tcg/voyager/routes/voyager.php in the try-catch block ).In order to solve this problem, I moved the data_types and data_rows tables in the central database (all tenants will share these tables). The last problem that I have is that some assets are not loading.

stancl commented 4 years ago

Hey,

There are no plans to support Voyager.

Since this is a support issue, if you still need help, you can visit our Discord and ask your community for help.

Mazharqwe commented 9 months ago

I already did, if someone interested please let me know