Skip to content
Advertisement

laravel avoid multiple Select’s Option in blade

simply in my controller i have this collections:

JavaScript

and in front end i try to check which users in $users is into $category->users, like with:

in Category model which that belong to User i have one or multiple stored users and i would like checked html option if each $category has user which that is into $user

JavaScript

this code and compare works, but i have multiple <option> which they are maybe selected or not. how can i solve this issue?

Advertisement

Answer

You can loop over the collection which is in the $users variable, and use the contains method to check if the current user id in the loop is contained in the $category->users collection.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement