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

Daghsny's avatar

Undefined Variable Livewire problem

he say always that: Undefined variable $count

the php livewire class

<?php

namespace App\Livewire\Course;

use Livewire\Component;

class Index extends Component
{
    public $count = 'hello';
    public function render()
    { 
        return view('livewire.index');
    }
}

the blade view

<div>
{{$count}}
hello from the index 
</div>

the route


Route::view('/test', 'livewire.index');
1 like
7 replies
Daghsny's avatar

@Sinnbeck i have formatting it, all my project run corectly, But when i trying to create a new component . he stop sendin meme the simple variable :/

Daghsny's avatar

@Sinnbeck

Route::view('/test',  TestIndex::class);

if i remove the variable from the view, the view render correclty, but the problem if i bind the variable

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Daghsny Yes. It isnt set. If you call the view directly, livewire has no clue it has to do anything. Do one of the solutions I already suggested..

Also your code is wrong. Its get() not view()

Route::get('/test',  TestIndex::class);

And why is it now TestIndex? Your first post said it was called Index ?

1 like
Sinnbeck's avatar

@Daghsny Happy to help. Please mark the thread as solved by marking the answer that helped you :)

1 like

Please or to participate in this conversation.