hipsterjazzbo / Landlord

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

Polymorphism #8

Closed igortrinidad closed 8 years ago

igortrinidad commented 8 years ago

Hi guys,

Please, can you tell me how to make the scope of my queries with the package using polymorphism relationship?

Like how to set the type (tenant class) and the id (tenant id).

Thanks in advance!

DanielOlckers commented 8 years ago

Hi everyone,

Same question as @igortrinidad. Is there a way to do this already?

hipsterjazzbo commented 8 years ago

Sorry, I don't understand your question. Do you have an example?

igortrinidad commented 8 years ago

Hi Caleb,

Well we use the polymorphism that laravel provide to us, in some table we have messageable_id and messageable_type (it's the class of the model), so i'd like to know if the package could make the scope based on this two points (id and type) in the queries...

Cause we could have two or more id's that doesn't mean the same entity, could be some id of client, and manager whatever...

But till now we're doing this by hand actually...

hipsterjazzbo commented 8 years ago

Hmm I see.

In theory, you could set this up. I can't tell you what the logic would be to decide what values to use, as that's specific to your app, but you can set two "tenants":

Landlord::addTenant('messagable_id', $whatever);
Landlord::addTenant('messagable_type', $whatever);

Does that help?

igortrinidad commented 8 years ago

Woww that's awesome! I never thought about it... oO

Thanks for your attention and to keep the project!

hipsterjazzbo commented 8 years ago

No problem. Good luck!