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.
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 becauseenabled
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.