Old Value for Checkbox Multiple - Laravel

Posted 3 months ago by nonanovi

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

Please sign in or create an account to participate in this conversation.