Livewire Error: public property [message] must be of type: [numeric, string, array, null, or boolean]

  laravel, laravel-livewire

I am getting this issue, and I don’t understand what I am doing wrong as I did this same exact approach for another component on this site, and works perfectly….

ViewMessages.php

public $messages;

public function mount($messages)
    {
        $this->messages = $messages;
    }

view-messages.blade.php

<div class="flex flex-col">
        @foreach ($messages as $message)
                {{$message->content}}
        @endforeach
</div>

Everything works and it outputs all the messages correctly.

When I try and pass in a livewire component into the for each, it gives that error.

@foreach ($messages as $message)
       @livewire('chat.show-message', ['message'=>$message], key('show-message-'.$message->id))
@endforeach

// ShowMessage.php
public $user;
    public $message;
    public $user_id;
    public $content;
  

    public function mount($message)
    {
        $this->message = $message;
    }

Honestly am lost on what I am doing wrong, as I copied the exact same code and changed the variables that I used before. It works right now on the site when I do nested components.

<div class="flex flex-col space-y-4 py-4 overflow-y-auto">
     @foreach ($chats as $chat)
          @livewire('kanbans.show-sidebar-chat-message', ['chat'=>$chat], key('chat-'.$chat->id))
     @endforeach
</div>

I redid this component already twice, and can’t find any syntax issues or spelling errors. =/

Source: Laravel

Leave a Reply