tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 393 forks source link

force-tenant-connection-of-models fails with Laravel Spark #499

Closed kylekz closed 6 years ago

kylekz commented 6 years ago

Description

Installed Laravel Spark, added its models to the force-tenant-connection-of-models array and they're still forcing themselves onto the system connection. May not be strictly Spark related, it's just what I'm running into issues with. Talking with luceos on Discord, we've tried:

We were thinking it may be relation related, but where the code is failing, it's accessing the Notification model and querying it directly rather than off a relation.


Actual behavior

Forces itself to the system connection where the table doesn't exist. See error log below.

Expected behavior

Should use the tenant connection to find the correct prefixed table.


Information


tenancy.php config

https://gist.github.com/xKairu/734a1258c87d5cd2a2909dd0e735fed1

LIMIT_UUID_LENGTH_32=true
TENANCY_DIRECTORY_AUTO_DELETE=true
TENANCY_DATABASE_AUTO_DELETE=true
TENANCY_DATABASE_AUTO_DELETE_USER=true
TENANCY_DATABASE_DIVISION_MODE=prefix
TENANCY_EARLY_IDENTIFICATION=true
TENANCY_DEFAULT_CONNECTION=system

webserver.php config

https://gist.github.com/xKairu/59da2d10bfcd2e7db12bb8d235067c27


Error log

https://gist.github.com/xKairu/2d2425fa7f8fcecd6a015f572621e58b

kylekz commented 6 years ago

Just updated to 5.2 beta and the issue still persists. Other than hardcoding changes to Spark itself, I haven't found any solution either.

luceos commented 6 years ago

So...

A solution would be to add the Tenancy service provider inside config/app.php so that it is registered before the Spark service provider (automatically) and to enable early/eager identification so that the event is being listened on.

There are alternatives to this solution I might suggest but they would require changes to the package.. I'd love to hear first whether my hunch was correct and the above solves your issue.

kylekz commented 6 years ago

Added tenancy to the don’t discover in composer.json, added tenancy’s provider above Spark, enabled early identification, cleared caches etc etc. Still getting the same error.

Edit: Updated stacktrace: https://gist.github.com/xKairu/231f7a0c08e1929c7d54f8f82d78069a

luceos commented 6 years ago

This should have been fixed, please confirm and re-open in case it still causes troubles.