Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

petervandijck's avatar

In Livewire 3, how do I get a model data into the view

Hi, I'm using Livewire 3. I'm struggling with sending variables to Blade. - in the below example, I get an error from Blade: "Undefined variable $analytics_topic"

For context: I'm a beginner :)

The Blade template is this:

Date is {{ $analytics_topic->conversation_date }}

The Livewire component looks like this:

<?php

namespace App\Livewire;

use Livewire\Component;
use Livewire\Attributes\On;
use App\Models\AnalyticsTopic;

class SidebarTopicDetail extends Component
{
    public $topicId = null;

    #[On('show-sidebar-topic-detail')] // When that event happens (on click on a topic in the frontend)
    public function showSidebar($topicId)
    {
        // ...
        $this->topicId = $topicId; // set our internal variable topicId to the one we received
        $this->analytics_topic = AnalyticsTopic::find($topicId);
    }

}
0 likes
1 reply
petervandijck's avatar

I found the solution, I had forgotten to add this: public $analytics_topic = null;

Please or to participate in this conversation.