Livewire: I’m getting this error message: “Cannot assign array to property AppLivewireToggleButton…”

Hy Guys,

I’m getting this error message:

“Cannot assign array to property AppLivewireToggleButton::$model of type IlluminateDatabaseEloquentModel”

Below are the code lines.

edit-setup.blade.php

<tbody class="bg-white">
@foreach ($tetrazolios as $index => $tetrazolio)

    <tr>

        <td class="px-6 py-4 whitespace-no-wrap border-b border-gray-500 text-sm leading-5">
            @if ($editedTetrazolioIndex === $index || $editedTetrazolioField === $index . '.limit')
                <input type="text"
                       wire:model="tetrazolios.{{ $index }}.limit"
                    @class([
                         'mt-2 text-sm sm:text-base pl-2 pr-4 rounded-lg border w-full py-2 focus:outline-none focus:border-blue-400',
                         'border-red-500' => $errors->has('tetrazolios.' . $index . '.name'),
                         'border-gray-400' => ! $errors->has('tetrazolios.' . $index . '.name'),
                    ])
                />
                @error('$tetrazolios.' . $index . '.limit')
                    <div class="text-red-500 mt-1">{{ $message }}</div>
                @enderror
            @else
                <div class="cursor-pointer" wire:click="editTetrazolioField({{ $index }}, 'limit')">
                    {{ $tetrazolio['limit'] }}
                </div>
            @endif
        </td>

        <td class="px-6 py-4 whitespace-no-wrap border-b border-gray-500 text-sm leading-5">
            @if ($editedTetrazolioIndex === $index || $editedTetrazolioField === $index . '.weight')
                <input type="text"
                       wire:model="tetrazolios.{{ $index }}.weight"
                    @class([
                         'mt-2 text-sm sm:text-base pl-2 pr-4 rounded-lg border w-full py-2 focus:outline-none focus:border-blue-400',
                         'border-red-500' => $errors->has('tetrazolios.' . $index . '.name'),
                         'border-gray-400' => ! $errors->has('tetrazolios.' . $index . '.name'),
                    ])
                />
                @error('tetrazolios.' . $index . '.weight')
                <span class="text-red-500 mt-1">{{ $message }}</span>
                @enderror
            @else
                <div class="cursor-pointer" wire:click="editTetrazolioField({{ $index }}, 'weight')">
                    {{ $tetrazolio['weight'] }}
                </div>
            @endif
        </td>


        <td class="px-6 py-4 whitespace-no-wrap border-b border-gray-500 text-sm leading-5">
            <livewire:toggle-button
                :model="$tetrazolio"
                field="enabled"
            />
        </td>

        <td class="px-6 py-4 whitespace-no-wrap border-b border-gray-500 text-sm leading-5">
            @if($editedTetrazolioIndex === $index || (isset($editedTetrazolioField) && (int)(explode('.',$editedTetrazolioField)[0])===$index))
                <button
                    class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray disabled:opacity-25 transition ease-in-out duration-150"
                    wire:click="saveTetrazolio({{$index}})">
                    Salva
                </button>
            @else
                <button
                    class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray disabled:opacity-25 transition ease-in-out duration-150"
                    wire:click="editTetrazolio({{$index}})">
                    Edita
                </button>
            @endif
        </td>
    </tr>

@endforeach
</tbody>

App/Livewire/ToggleButton.php

<?php

namespace AppLivewire;

use IlluminateContractsViewView;
use IlluminateDatabaseEloquentModel;
use LivewireComponent;

class ToggleButton extends Component
{
    public Model $model;

    public string $field;

    public bool $enabled;

    public function mount(): void
    {
        $this->enabled = (bool) $this->model->getAttribute($this->field);
    }

    public function render(): View
    {
        return view('livewire.toggle-button');
    }

    public function updating($field, $value): void
    {
        $this->model->setAttribute($this->field, $value)->save();
    }
}

var_dump $tetrazolio

array:10 [▼ // resourcesviews/livewire/admin/setups/edit-setup.blade.php
  "id" => 271
  "setup_id" => 9
  "company_id" => 1
  "tetrazolio_id" => 1
  "step" => "1"
  "limit" => "90"
  "weight" => "25"
  "enabled" => 1
  "created_at" => "2024-06-21T20:00:49.000000Z"
  "updated_at" => "2024-07-01T12:41:37.000000Z"
]

I want to implement Tailwind Toggle Switch to enable and disable a record.

New contributor

Clayton Montarroyos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật