hipsterjazzbo / Landlord

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

Multiple Tenant Columns, Disable Just One? #32

Closed aronduby closed 7 years ago

aronduby commented 8 years ago

My setup has 2 different tenant columns: site_id and season_id. For the large majority of things I want both of them. However there are a few queries where I actually want to ignore the season_id tenant while still keeping the site_id. Is there an easy way to do that that I'm just not seeing?

It looks like I might be able to pull it off but it would involve globally removing it, doing the query, and then globally adding it back in as soon as it's done. That's just not pretty.

aluferraz commented 8 years ago

+1

hipsterjazzbo commented 7 years ago

I'd love comments on this. I've been mulling around a bit of a refactor for this to make that sort of thing easier.

limatheus commented 7 years ago

This feature would be very interesting.

+1

hipsterjazzbo commented 7 years ago

The next version that I've been testing with some of my stuff this week registers a separate, anonymous global scope for each tenant, enabling syntax like this:

Model::withoutScope('tenant_id')->get();

I'm still playing with the syntax a bit, and making sure it's well tested. Also looking at including some default middleware or something to help those people who are not as familier with the whole stack to get started.

I'll try to tag a beta today.

hipsterjazzbo commented 7 years ago

Hey guys. Try the v2.0-wip branch. There are still a few tests missing, and I haven't yet had time to document the breaking changes, but just go through the readme and you should be okay. Mostly some classes and methods have been renamed to more closely match what they're actually doing now.

v2.0 uses anonymous global scopes under the hood, so you should be able to do something like

Model::withoutGlobalScope('tenant_id')->get();