Replies: 2 comments 2 replies
-
Wondering the same. <?php
namespace App\Policies;
use App\Models\Event;
use App\Models\User;
class EventPolicy
{
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
*
* @return bool
*/
public function viewAny(User $user): bool
{
setPermissionsTeamId($user->currentTeam->id);
return (
$user->can('events.view-all')
);
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\Event $team
*
* @return bool
*/
public function view(User $user, Event $team): bool
{
setPermissionsTeamId($user->currentTeam->id);
return (
$user->can('events.view') &&
$user->currentTeam->events->contains($team->id)
);
}<?php
namespace App\Policies;
use App\Models\Event;
use App\Models\User;
class EventPolicy
{
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
*
* @return bool
*/
public function viewAny(User $user): bool
{
setPermissionsTeamId($user->currentTeam->id);
return (
$user->can('events.view-all')
);
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\Event $team
*
* @return bool
*/
public function view(User $user, Event $team): bool
{
setPermissionsTeamId($user->currentTeam->id);
return (
$user->can('events.view') &&
$user->currentTeam->events->contains($team->id)
);
}
} But feels a bit weird to do |
Beta Was this translation helpful? Give feedback.
-
To answer my question to others / my future self if I forget. The answer is a Global Role needs to be attached for the user for every team. That's the part I was not implementing properly. Example This means my model_has_roles table will have 1000 rows of role_id 1 and user_id 1 along with the 1000 teams. |
Beta Was this translation helpful? Give feedback.
-
https://spatie.be/docs/laravel-permission/v6/basic-usage/teams-permissions
I am confused and I want to make sure I understand this properly.
I want to access all the roles a user has on the current team, plus all the roles and permissions they have at the global level.
Does that mean I need to do the following or is there a better way?
Beta Was this translation helpful? Give feedback.
All reactions