livewire / volt

Volt is an elegantly crafted functional API for Livewire.
https://livewire.laravel.com/docs/volt
MIT License
359 stars 19 forks source link

Volt documented example showing error #99

Closed joydeep-bhowmik closed 8 months ago

joydeep-bhowmik commented 8 months ago

Volt Version

1.6.2

Laravel Version

10.10

PHP Version

8.2.12

Database Driver & Version

No response

Description

<?php

use function Livewire\Volt\{state};

state('count');

$increment = function () {
    // Store the new count value in the database...

    $this->count++;
};

?>

<x-app-layout>
    <x-slot name="header">
        Initial value: {{ $count }}
    </x-slot>

    @volt('counter')
        <div>
            <h1>{{ $count }}</h1>
            <button wire:click="increment">+</button>
        </div>
    @endvolt
</x-app-layout>

This example returns Undefined variable $count for Initial value: {{ $count }}

Steps To Reproduce

just install volt 1.6.2 and use the mentioned example

driesvints commented 8 months ago

Just works for me.

joydeep-bhowmik commented 8 months ago

Just works for me.

any possible reason it's not working for me? I did clear the compiled views My livewire version: 3.4 My volt version:1.6.2

I installed volt with breeze


  <x-slot name="header">
        Initial value: {{ $count }}
    </x-slot>

This $count variable is returning undefined not the $count variable inside volt directive

kemalozvarol2 commented 1 month ago

Same error happening with me too. Have you found a solution?

Versions : livewire/livewire : ^3.5 (v3.5.9) livewire/volt : ^1.6 (v1.6.5) laravel/framework : ^11.9(v11.26.0)

joydeep-bhowmik commented 1 month ago

Same error happening with me too. Have you found a solution?

Versions : livewire/livewire : ^3.5 (v3.5.9) livewire/volt : ^1.6 (v1.6.5) laravel/framework : ^11.9(v11.26.0)

nope still no solution to this ... seems like livewire variables are only available within volt directives

kemalozvarol2 commented 1 month ago

nope still no solution to this ... seems like livewire variables are only available within volt directives

Mine was solved when I called the component from a blade file. I was returning the component directly from a route like;

Route::view('counter', 'livewire.counter');

I changed it to

Route::view('welcome');

And in the welcome.blade.php I put :

<livewire:counter />

Were you also trying to return the component from the route file?

philharmonie commented 1 month ago

nope still no solution to this ... seems like livewire variables are only available within volt directives

Mine was solved when I called the component from a blade file. I was returning the component directly from a route like;

Route::view('counter', 'livewire.counter');

I changed it to

Route::view('welcome');

And in the welcome.blade.php I put :

<livewire:counter />

Were you also trying to return the component from the route file?

That's the solution to the issue. But to solve the issue, alternatively a full page component render would work as well:

use Livewire\Volt\Volt;

Volt::route('/counter', 'counter');