Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nonanovi's avatar

Old Value for Checkbox Multiple - Laravel

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 :(

0 likes
2 replies
ftiersch's avatar
ftiersch
Best Answer
Level 28

Use this:

$variant->tags->pluck('id')->toArray()
nonanovi's avatar

@FTIERSCH - uh, this is exactly what i need, got dizzy for 1 day anyway :( thank you :)))

Please or to participate in this conversation.