hipsterjazzbo / Landlord

A simple, single database multi-tenancy solution for Laravel 5.2+
MIT License
615 stars 138 forks source link

Support for deferred scope apply for Models booted before Tenant setup #66

Closed renanwilliam closed 6 years ago

renanwilliam commented 7 years ago

Solution provided by pimski for deferred scope apply to models booted before Tenants setup.

ryross commented 7 years ago

Any chance we can get this merged or reviewed?

ryross commented 7 years ago

I was actually hoping this solved the issue where applying the tenant scope in a group middleware doesn't work, but that isn't the case with this PR

ryross commented 7 years ago

Nevermind on my last comment. I missed the part where I need to run Landlord::applyTenantScopesToDeferredModels(); after the Landlord::addTenant() call. Works for me! Thanks @renanwilliam and @pimski

ryross commented 6 years ago

@renanwilliam would you mind explaining what the 2nd and 3rd commits fix? I have two tenant scopes and the first() logic is incorrectly choosing which tenant scope to apply

renanwilliam commented 6 years ago

@ryross it's for the cases when I change the tenant before a scope is applied.

ryross commented 6 years ago

@renanwilliam You might want to find a different way to do that. Your logic breaks the code for folks who have two tenants. It resets the ID. @HipsterJazzbo Did you test this?

renanwilliam commented 6 years ago

Hi @ryross , I have executed all previous test cases and the new test case write for the change and it not happens, no problems for me (we are also using it in a production project with 5 tenants and everything looks fine). Do you have a test case or instructions do check this error?