Setting and getting multiple team ids in the session for user
Description
I need to be able to be assigned to multiple "teams", in our system we call these "companies" at any one given time. Right now it seems that the package only supports setting a single ID in the session, is there anyway that I can set multiples, e.g:
Here's the methods that your package is defining:
if (! function_exists('setPermissionsTeamId')) {
/**
* @param int|string|null|\Illuminate\Database\Eloquent\Model $id
*/
function setPermissionsTeamId($id)
{
app(\Spatie\Permission\PermissionRegistrar::class)->setPermissionsTeamId($id);
}
}
if (! function_exists('getPermissionsTeamId')) {
/**
* @return int|string|null
*/
function getPermissionsTeamId()
{
return app(\Spatie\Permission\PermissionRegistrar::class)->getPermissionsTeamId();
}
}
Steps To Reproduce
Check the docs
Example Application
No response
Version of spatie/laravel-permission package:
6.16.0
Version of laravel/framework package:
12.6.0
PHP version:
8.3.19
Database engine and version:
No response
OS: Windows/Mac/Linux version:
No response
Is it correct to presume that your intention is that setting multiple teams into the session is only for the purpose of querying permission/ability authorization against all specified multiple teams?
Considerations that come to mind:
-
How would one's app decide when a User's permissions should be checked against one team vs multiple teams and "which" multiple teams. I suppose the TeamID could be treated as an array instead of an integer. And then methods could be offered to add additional teams into that array.
-
Relationship lookup queries (used for ability checking) would have to change from
=toIN()or= OR = OR =, etc, and those are slightly less performant, and a little more tenuous to manage. If the session variable is an array with a single value we could use the present relationship, and if the array has more than one value then we could useIN()logic. -
Cache: additional attention to cached results may be needed, such as when specifying additional teams to set to or removed from the array
-
All methods that assign/remove permissions/roles would need rewriting to require a specific team ID instead of relying on session lookup, since we could no longer depend on the session variable to be a single integer.
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.