10 months ago

Edit Many to Many with two foreach?

Posted 10 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)) }}



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.