The issue you're encountering is due to the fact that the $key in your second array is an object, not a primitive value like a string or number. When you try to use an object as the value of an HTML attribute, it gets converted to the string "[object Object]".
To fix this, you need to ensure that the $key is a primitive value. If the $key is an object, you should convert it to a string or extract a property from it that can be used as a value.
Here's a modified version of your Blade template that checks if the $key is an object and converts it to a string if necessary:
@foreach($filters->$method() as $key => $value)
@php
// Check if $key is an object and convert it to a string if necessary
$keyValue = is_object($key) ? json_encode($key) : $key;
@endphp
<label class="flex flex-row space-x-3 text-xs" wire:key="{{ $method }}-{{ $keyValue }}">
<input type="checkbox" wire:model.live="filters.{{ $method }}SelectedIds" value="{{ $keyValue }}">
<span>{{ $value }}</span>
</label>
@endforeach
In this solution, we use the json_encode function to convert the object to a JSON string if $key is an object. This ensures that the value attribute of the checkbox will always be a string.
If you know the structure of the object and you want to use a specific property of the object as the value, you can adjust the code accordingly. For example, if the object has an id property that you want to use:
@foreach($filters->$method() as $key => $value)
@php
// Use the 'id' property of the object if $key is an object
$keyValue = is_object($key) ? $key->id : $key;
@endphp
<label class="flex flex-row space-x-3 text-xs" wire:key="{{ $method }}-{{ $keyValue }}">
<input type="checkbox" wire:model.live="filters.{{ $method }}SelectedIds" value="{{ $keyValue }}">
<span>{{ $value }}</span>
</label>
@endforeach
This way, you can ensure that the value attribute is correctly set based on the structure of your data.