Level 28
Use this:
$variant->tags->pluck('id')->toArray()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
so, i make a checkbox multiple on my edit.blade.php some of the checkbox value are checked but the rest are not. i make an if condition using in_array, the accepted value for the second param of in_array function is array NOT an object, ex : [1,2,3] but in this case what i have is an object. so, i cast that object into array but what i actually need is an array of this value :
foreach($variant->tags as $val)
$val->id // this value
endforeach
this is my html code
@foreach($tags as $tag)
@if(in_array($tag->id, $variant->tags->toArray()))
<input type="checkbox" name="tag[]" value="{{ $tag->id }}" checked> {{ $tag->name }}
@else
<input type="checkbox" name="tag[]" value="{{ $tag->id }}"> {{ $tag->name }}
@endif
@endforeach
anyone of you know what to do to solve this, please :(
Use this:
$variant->tags->pluck('id')->toArray()
Please or to participate in this conversation.