hipsterjazzbo / Landlord

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

Disable tenant scope in closure #81

Open mbaeuerle opened 6 years ago

mbaeuerle commented 6 years ago

Currently disabling Landlord with disable() just affects new types of models and newly created models but not models where the scope has already been added to. This is because enabled is checked only when a scope should be added to a model but not when the scope is applied to an actual query.

In this PR I moved the enabled-check to the global scope closure so the tenant scope is never applied if it was disabled previously which is the expected behavior in my opinion. This is also the behavior of Landlord 1.

I also moved the global scope code into a private method to reduce duplication.