1

I know how to assign permissions to user.

class User extends Authenticatable
{
   use HasRoles;
}

$user->givePermissionTo('edit articles');

In this case, in model_has_permissions table will be inserted like this.

permission_id=> $permission_id
model_type=> "App\Models\User"
model_id=> $user_id

I have Team Model and I want to give permission to Team too. This is what I did.

class Teamextends Authenticatable
{
   use HasRoles;
}

$team->givePermissionTo('edit articles');

I wanted this result,

permission_id=> $permission_id
model_type=> "App\Models\Team"
model_id=> $team_id

But it didn't work for me. Anyone has experience such as above things? Should I make another table for it? like team_has_permission?

apokryfos
  • 38,771
  • 9
  • 70
  • 114
LoveCoding
  • 1,121
  • 2
  • 12
  • 33

1 Answers1

1

I found solution!

class Team extends Authenticatable
{
   use HasRoles;
   protected $guard_name = 'web';
}

$team->givePermissionTo('edit articles');

This worked well. In db table, it saved like this.

permission_id=> $permission_id
model_type=> "App\Models\Team"
model_id=> $team_id

Really awesome!

LoveCoding
  • 1,121
  • 2
  • 12
  • 33
  • 1
    this solution works for me, tried different things but this is the simplest solution we have for this issue, thanks bro. – Moaz Ateeq Sep 23 '21 at 08:34