RoffDaniel's avatar

Why Livewire returned me Undefined variable?

Hello every body! Tell me please, why Livewire component returned me undefined variable? This is my component code:

<?php

namespace App\Livewire;

use Livewire\Component;

class CreatePost extends Component
{
    public $title = 'Post title...';
    public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
    {
        return view('livewire.create-post');
    }
}

P.S: code from livewire.laravel.com - https://livewire.laravel.com/docs/components#setting-properties

And my blade code:

<div>
    {{ $test }}
</div>

I don't understand, why... What I do wrong? Thanks in advance!

0 likes
3 replies
fcno's avatar

Dear @RoffDaniel ,

Snapey ended up showing that the solution was trivial. But the correct thing would be, instead of saying that you solved it yourself, to explain what the problem was and what the solution was.

The way you responded and even marking your answer as the 'best answer' shows a certain selfishness on your part. After all, you shared the problem with the community and asked for help to solve your problem, but when you solved the problem, you didn't share the solution, but rather kept it to yourself.

In fact, in my opinion, the 'best answer' should be Snapey's and not yours.

Snapey's avatar

$test versus $title seems the obvious answer

1 like

Please or to participate in this conversation.