The SessionGuard is macroable which means you can methods to it at runtime.
Add this to your AuthServiceProvider's boot method:
// ./app/Providers/AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
SessionGuard::macro('currentTeamId', function () {
return session('current_team_id'); // use you actual session variable
});
SessionGuard::macro('userHasRoleInCurrentTeam', function ($team) {
return true; // add custom logic
});
}
Some references to understand how macros work:
https://tighten.co/blog/the-magic-of-laravel-macros/
https://www.manifest.uk.com/blog/understanding-laravels-macroable-trait
The docs only mentions it for Collections, but it work for every "Macroable" class:
https://laravel.com/docs/8.x/collections#extending-collections