Edit Many to Many with two foreach?

Posted 7 months ago by Juliano_RS

Hi, i am learning laravel.

I trying to do a list of movies with genders. Movies and genders have a many to many relationship. I trying to edit this fields and bring the value of each gender related with the movie. I have this:

@foreach($movie->genders as $mgender) {{-- return 2 genders --}}

@foreach($genders as $gender) {{-- return 7 all gende --}}

<option {{ $gender->id == $mgender->id ? 'selected' : '' }} value="{{ $gender->id }}">

{{ ($gender->title)) }}

@endforeach

@endforeach

The result list is duplicated (14). How can i get return a list with unique values (7)?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.