Answer the question
In order to leave comments, you need to log in
Check existing items when listing user data?
there is a table of interests
$interests = Interest::where('published','=',1)->get();
$userInterests = UserInterest::where('user_id', '=', Auth::user()->id)->get();
@forelse($user_interests as $interest)
<li>
<div class="checkbox-input">
<input type="checkbox" id="interest_{{$interest->id}}" name="interests[]" @isset($user_interests){{ in_array( $interest->id, $interests ) ? ' checked' : '' }} @endisset value="{{$interest->id}}">
<label for="interest_{{$interest->id}}">{{$interest->title}}</label>
</div>
</li>
@empty
@endforelse
Answer the question
In order to leave comments, you need to log in
$userInterests = UserInterest::where('user_id', Auth::id())->pluck('interest_id');
{{ $userInterests->contains($interest->id) ? ' checked' : '' }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question