Returning checked checkboxes based on pivot table


#1

Many users can belong to many teams. I have a pivot table team_user to manage the many-to-many relationship.

I am having trouble populating the checkboxes based on whether the association exists in the pivot table.

Is there anyting like:

@each(team in teams)
    <input {{ user.teams.contains(team.id) ? 'checked' : ''}}>
@endeach

Thx in advance


#2

@patrikalbertsson

Your question is missing lots of information, without which it’s almost impossible to answer the question.

  1. What is the structure of data for teams, Simply console.log(JSON.stringify(teams, null, 2)) inside your controller and share that.

  2. Also share the code, where you pass teams to your view while calling view.render