Product filters and Livewire component

Hello everyone. I’m trying to make product filters.

Difficult part is that all product attributes NOT hardcoded in product model, there’s another model Attribute. And attributes can be added in admin panel by admin user. For example, admin user can add new attribute “screen size”, tomorrow “disk space”, etc.

So all attributes is like variables and problem is - how to set them as constants in Livewire component for filtering products. Here:

class CatalogFilter extends Component
{
    public ?first attribute?
    public ?second attribute?

    public function render()
    {
        $first attribute= $this->first attribute;
        $second attribute= $this->second attribute;

Blade:

@foreach($attributes as $attribute)
            <div class="form-group mb-4">
                {{ $attribute->name }}

                @foreach($attribute->products as $attr)
                    <div class="form-group mb-0">
                        <label for="{{ $attr->pivot->value_id }}">
                            <input type="checkbox" wire:model.debounce.500ms="{{ $attribute->code }}" id="{{ $attr->pivot->value_id }}" value="{{ $attr->pivot->value }}" checked>
                            {{ $attr->pivot->value }}
                        </label>
                    </div>
                @endforeach
            </div>
        @endforeach

Hi,
You need to select all attributes and bind it to an array property then you can set it with no problems.

Livewire Docs example

Binding Nested Data

Livewire supports binding to nested data inside arrays using dot notation:

<input type="text" wire:model="property.attribute">

here an example, i helped someone with similar problem
https://forum.laravel-livewire.com/t/binding-dynamicaly-generated-inputs/3423/2