0
votes

I've got the following tables in the DB architecture:

  • users (id, name, surname)
  • teams (id, name)
  • roles (id, name)
  • permissions (id, name)
  • team_role_permission (team_id, role_id, permission_id)
  • team_user (user_id, team_id, role_id)

My goal is to describe the relation between team, role and permission models. I read the Laravel documentation and there's no way to use the pivot table with 3 relations. Actually, I'll use only 3 relations:

  • In what teams the player is and what is his role in each team (method teams in the User/Player model)
  • Which players are in the team and what is their roles (method players in the Team model)

But I don't understand how to use it with laravel relations?

The table team_role_permission and it's relations have to be, because team creator should be able to edit permissions for his (each) team manually.

1

1 Answers

0
votes

possible solution could be storing manually in your pivot table. you should create a model for your pivot table.

$team = Team::create();
$role = Role::create();
$permission = Permission::create();

$pivot = new TeamRolePermission();
$pivot['team_id'] = $team->id;
$pivot['role_id'] = $role->id;
$pivot['permission_id'] = $permission->id;
$pivot->save();