is there any way to interrupt and change the components and scopes of an eloquent query?
in order to add multitenancy to an existing project, I've added a global scope to my models, filtering results by tenant_id. and it works fine.
the problem is I have found more than 500 hardcoded 'where conditions ' and 'create statements' all over the place. such as these:
$notification_type= NotificationTypes::where('id', '2')->get();
or
$tickets = Tickets::create( $title, $body, $sender, '1'); // 1 as statusID
etc.
It's a problem because I'm using the single DB approach for multitenancy and these IDs must be relative to the tenant. for Example in the first query above, I don't want the 'NotificationTypes' with Id of '2', But I want the 'second' NotificationType with that tenant_id (id of this column could be 4 or 7 or else).
I can figure out a way to properly calculate the exact amount of these Relative IDs. but is there any way to find the prior scope and conditions of an eloquent object and change them?
I'm looking for a way to add multitenancy to the project without changing much of the existing code. like a module or plugin.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire