Giter Club home page Giter Club logo

volt's Introduction

Livewire Logo

Total Downloads Latest Stable Version License

Introduction

Livewire is a full-stack framework for Laravel that allows you to build dynamic UI components without leaving PHP.

Official Documentation

You can read the official documentation on the Livewire website.

Contributing

Thank you for considering contributing to Livewire! You can read the contribution guide here.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by Laravel's Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Livewire is open-sourced software licensed under the MIT license.

volt's People

Contributors

bekepr avatar bookwyrm avatar crynobone avatar devajmeireles avatar driesvints avatar jessarcher avatar joaopalopes24 avatar lee-to avatar nuernbergera avatar nunomaduro avatar robsontenorio avatar rvxlab avatar shuvroroy avatar taylorotwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

volt's Issues

Call to undefined method Livewire\Volt\LivewireManager::styles()

Volt Version

v1.0.0-beta.2

Laravel Version

10.17

PHP Version

8.2.8

Database Driver & Version

No response

Description

I get:

Call to undefined method Livewire\Volt\LivewireManager::styles()

for

@livewireStyles

Isn't it possible to use "old" livewire together with volt? Is it either one or the other?

Steps To Reproduce

Installed Volt into an existing project, that already used livewire:

composer require livewire/livewire "^3.0@beta"
composer require livewire/volt "^1.0@beta"

Now I get:

Call to undefined method Livewire\Volt\LivewireManager::styles()

for

@livewireStyles

Segmentation fault (core dumped) error when using route:cache command

Volt Version

1.1.0

Laravel Version

10.21

PHP Version

8.1.22

Database Driver & Version

8.0.30

Description

image

Segmentation fault error happen in the fresh installation on Livewire & Volt. When I ran artisan route:cache command. In the routes/web.php that have Volt Route, that error happen. When the volt route remove, route:cache command run succesfully.

Steps To Reproduce

  1. Install Livewire & Livewire Volt
  2. Create volt component. We call it "counter" component.
  3. Add Volt route to routes/web.php using this Volt::route('/counter', 'counter');
  4. Run artisan route:cache

Issue with Bus facade/batches in computed property

Volt Version

1.3.0

Laravel Version

10.10.0

PHP Version

8.2.3

Database Driver & Version

MySQL 8.0.28

Description

I don't know what's wrong but this code generates an error.

$batch = computed(fn () => Bus::findBatch($this->batchId));

// Even when I use a constant as batch ID like...
$batch = computed(fn () => Bus::findBatch('xxxxxxxx'));

image
image

Even if I create a variable to assign this expression on mount, same error.
But once I put something other than this expression, everything works.

I wonder whether it's caused by the Bus facade...

Here is how the view code looks like
image

Steps To Reproduce

In a Volt component (here anonymous), create a computed property retrieving a batch instance from the database.

Calling Volt::mount a second time negates initial call

Volt Version

1.3

Laravel Version

10.31.0

PHP Version

8.3.1

Database Driver & Version

No response

Description

Calling Volt::mount() more than once overwrites the first call. This makes it impossible for packages to use Volt::mount() to register their own components.

Steps To Reproduce

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Livewire\Volt\Volt;

class VoltServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        Volt::mount([
            config('livewire.view_path', resource_path('views/livewire')),
            resource_path('views/pages'),
        ]);

        Volt::mount([
            resource_path('views/vendor/demo/livewire'),
        ]);
    }
}

Install volt. Add code above to Volt service provider. Run php artisan make:volt counter. Use counter component in view.

Run the command below to copy the component to a new component called vendor-counter in the "vendor/demo" path set up in our provider.

mkdir -p resources/views/vendor/demo/livewire \
 && cp resources/views/livewire/counter.blade.php \
 resources/views/vendor/demo/livewire/vendor-counter.blade.php 

Attempt to use both in a view:

  @livewire('counter')
  @livewire('vendor-counter')

See error:

InvalidArgumentException
PHP 8.3.1
10.41.0
View [counter] not found.

counter was not found.
Are you sure the view exists and is a .blade.php file?

example repo: https://github.com/inmanturbo/volt-bug-report

php blocks don't work as expected in anonymous volt components

Volt Version

1.3.2

Laravel Version

10.24.0

PHP Version

8.2.10

Database Driver & Version

N/A

Description

Undefined variable for variable declared within @php block

Steps To Reproduce

<?php

use function Livewire\Volt\{state};

state(['count' => 0]);

?>

<div>
@volt('mycomponent')
    <div>
    @php
        $number = 3;
    @endphp
    <div>
        {{ $number }}
    </div>
    </div>
@endvolt
ErrorException
PHP 8.2.10
10.24.0
Undefined variable $number
    <div>

    |---LINE:13---|@__raw_block_0__@

    <div>

        |---LINE:17---|{{ $number }}

    </div>

    </div>

|---LINE:20---|

Demo repo:
https://github.com/inmanturbo/volt-bug-report

ADDITIONAL INFO (EDIT):
If you avoid the error by not attempting to use the variable, you will see @__raw_block_0__@ in your browser.

Example use case:

@foreach($this->posts as $post)
    @php
       if($post->getThirdPartyService()?->getResource() && $loop->index % 2 == 0) {
           // set styles etc
           $myComponentClass = 'bg-indigo-100';

       }elseif($post->getThirdPartyService()?->getResource()){

           $myComponentClass = 'bg-green-100';

       }elseif( .. other conditions ...){

           // etc
       }
    @endphp

     <x-my-component :class='$myComponentClass' />
....
@endforeach

Change layout for component-based Volt?

Is it possible to change the layout when using a full-page class-based Volt component?

What I need

new class extends Component {

      protected string $layout = 'components.layouts.guest';

}

What I tried

I tried just including the function and following it with the class declaration, but it didn't work:

layout('components.layouts.guest');

new class extends Component { ... }

P.S. Volt is really cool, thanks for all your collective work on it!

Can't use closures for validation

Volt Version

1.4

Laravel Version

10.31.0

PHP Version

8.2

Database Driver & Version

mariadb 10.4.31

Description

When trying to setup dynamic validation for my component, I used a closure inside the rules function, but when I try to access the page with my component, I get the following error: array_merge(): Argument #2 must be of type array, Closure given.

Steps To Reproduce

  1. Create a livewire volt component
  2. Create a validation with a closure like, rules(fn () => [ 'name' => ['required'] ]);
  3. Reload the page.

error

ParseError due to invalid method name containing an integer

Volt Version

1.1

Laravel Version

10.21.0

PHP Version

8.2.8

Database Driver & Version

No response

Description

While using Laravel Volt with Livewire, encountering a ParseError with the message syntax error, unexpected integer "1". The error occurs in the compiled views stored in the storage/framework/views folder. All project dependencies are up to date. The code causing the error is embedded in the generated view file 362bf8caa4c3264313ab66655990e3a0.php.

Error Details

ParseError
PHP 8.2.8
10.21.0
syntax error, unexpected integer "1"
storage / framework / views / 362bf8caa4c3264313ab66655990e3a0.php : 28

362bf8caa4c3264313ab66655990e3a0.php file:

<?php

use Livewire\Volt\Actions;
use Livewire\Volt\CompileContext;
use Livewire\Volt\Contracts\Compiled;
use Livewire\Volt\Component;

new class extends Component implements Livewire\Volt\Contracts\FunctionalComponent
{
    public static CompileContext $__context;

    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

    public function mount()
    {
        (new Actions\InitializeState)->execute(static::$__context, $this, get_defined_vars());

        (new Actions\CallHook('mount'))->execute(static::$__context, $this, get_defined_vars());
    }

    public function getListeners()
    {
        $arguments = [static::$__context, $this, func_get_args()];

        return (new Actions\ResolveListeners)->execute(...$arguments);
    }

    public function 1Handler($id) 
    {
        $arguments = [static::$__context, $this, func_get_args()];

        return (new Actions\CallListener('1'))->execute(...$arguments);
    }

};

View Code Causing Error

<?php

use function Livewire\Volt\{state};
use function Livewire\Volt\{on};

on('shipment-selected', function ($id) {
    //...
});

?>

Steps To Reproduce

  1. Create a Laravel Volt component as per the provided sample code.
  2. Try to execute the application.
  3. Observe the ParseError.

state(['search'])->url() does not update the url in anonymous component

Volt Version

[email protected]

Laravel Version

10.6.1

PHP Version

8.2.8

Database Driver & Version

No response

Description

The url is not updating with the state. The search functionality IS working fine. Also manually typing in a query string into the url and hitting enter works as well

Steps To Reproduce

<?php
 
use App\Models\Post;
use function Livewire\Volt\{computed, state};
 
state(['search'])->url();
 
$posts = computed(function () {
    return Post::where('title', 'like', '%'.$this->search.'%')->get();
});
 
?>
 
<div>
    @volt('posts')
     <div>
      <input wire:model="search" type="search" placeholder="Search posts by title...">
   
      <h1>Search Results:</h1>
   
      <ul>
          @foreach($this->posts as $post)
              <li wire:key="{{ $post->id }}">{{ $post->title }}</li>
          @endforeach
      </ul>
    </div>
   @endvolt
</div>

Support for wire:navigate

It would be great if you could build your entire applications, using volt components across the board. Unfortunately, it doesn't seem like wire:navigate is supposed, when returning volt components in your routes.

Right now I'm using a Route::get() and returning the volt in view(). Not sure if it's the correct way, but that wire:navigate doesn't work with that. Also, a more elegant way to define a "volt route" would be cool. Like Volt::get() or Route::volt()

States, Multiples Declarations

Volt Version

v1.0.0@beta2

Laravel Version

latest

PHP Version

8.1.21

Database Driver & Version

SQLite

Description

I don't know if this is really a bug or expected behavior, anyway I'm reporting this in order to help.

  1. State with closure and non-closure:
<?php

use function Livewire\Volt\state;

state(['title' => fn () => $title], '');

👇

CleanShot 2023-08-01 at 1 08 15

  1. State with closure and variable with no value:
<?php

use function Livewire\Volt\state;

state(['title' => fn () => $title, 'description']);

👇

CleanShot 2023-08-01 at 1 09 29

Steps To Reproduce

Try to do the same thing as reported above.

setting page title

in livewire we can use attribute to set page title, however I saw no way how to in docs for volt

is there a function like title() we can use for this or am I missing something?

`wire:model` does not update the state or trigger rendering when combined with `->url()`

Volt Version

1.6.0

Laravel Version

10.37.3

PHP Version

8.3.0

Database Driver & Version

SQLite (n\a)

Description

When I type anything into the search field that has wire:model, the list doesn't update and there are no requests sent according to the devtools network tab.

Source code of the component based on the documentation example:
https://github.com/osbre/bug-report-volt-search/blob/6a50e5f38a55295a96ef2ef5ff78405bf20577a9/resources/views/livewire/users.blade.php#L1-L24

Steps To Reproduce

git clone [email protected]:osbre/bug-report-volt-search.git
cp .env.example .env
php artisan migrate --seed      # DB_CONNECTION will be set to SQLite, due to .env.example
php artisan key:generate
php artisan serve
open http://127.0.0.1:8000

Repository: https://github.com/osbre/bug-report-volt-search

Import of class outside @volt not recognized inside @volt

Volt Version

1.3.3

Laravel Version

10.28

PHP Version

8.2.10

Database Driver & Version

MySQL 8.0.30 for Windows 11

Description

If it's done this way it doesn't work:
Captura de tela 2023-10-13 153507
imports declared before @Volt are not recognized within @Volt
Captura de tela 2023-10-13 154745
Displays the following error:
Captura de tela 2023-10-13 155026

But if it's done this way, it works perfectly:
Captura de tela 2023-10-13 154625

Steps To Reproduce

Import a class/enum outside of @Volt and try to use the same inside @Volt @endvolt

Artisan command volt file generator not creating folders.

Volt Version

1.6

Laravel Version

10.10

PHP Version

8.2.4

Database Driver & Version

No response

Description

php artisan make:volt folder.counter

generated livewire\folder.counter.blade.php instead of creating livewire\folder\counter.php

Steps To Reproduce

run this command after installing livewire-volt
php artisan make:volt folder.counter

Dynamic page title for class based Volt component

I don't know if I'm missing something or this is just not implemented.

I need to add a title to a full page Volt component. I have this home page component

<?php
 
use Livewire\Attributes\{Title, Layout};

new class extends Livewire\Volt\Component {

#[Layout('components.layout')]

// this works, but for static title, 
// also works only if there is a function underneath it! so I had to add an empty with function to get rid of the error
#[Title('Home')]
function with(){ return [];} // it's here just to show the title!

// This doesn't work
// function title(){
    return __('Translated page title');
}

} ?>

<div>
    Home page
</div>

I render this component directly as volt route
Volt::route('/', 'home');

[Feature] Ability to assert if a page contains a Volt component.

Currently, there is no assertSeeVolt available on the TestResponse or TestView. I've found a way to achieve smoke testing for this using FragmentAlias::encode, it also works with FragmentMap::get. But the latter runs slower and sometimes cannot find a component, guessing it's because it's not in the look-up. 🤔

I submitted a PR earlier to add this to the documentation (livewire/livewire#6204) as an example for others. But given it's a hacky way to achieve the desired result.

Is there a way we could get assertSeeVolt added in a future beta release? 🙂

Livewire Volt::actingAs() method

I was writing test using PEST2,
Since I was using Volt and need to write test for function that have auth()->user(),
It was return null since no actingAs method to use in Volt Class.

Hope It would be better if Volt also have this function below.

Livewire::actingAs($user)
->test(UpdatePost::class, ['post' => $post])
->set('title', 'Living the lavender life')
->call('save')
->assertUnauthorized();

Code inside rendering method fired two times

Volt Version

1.3.3

Laravel Version

10.28.0

PHP Version

8.1.20

Database Driver & Version

No response

Description

Since Livewire Volt Doc not covered all the use case, so i'm not sure is this coding right.

The code inside rendering method fired two times.

May be we need a method to passing all data to Layout, NOT only ->title() method?

Steps To Reproduce

  1. Layout
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    ...

    <title>{{ $pageTitle }} - {{ config('app.name') }}</title>
    <meta name="description" content="{{ $pageDescription }}">
    <meta name="keywords" content="{{ $pageKeywords }}">

    ...
</head>

<body>
    <main>
        {{ $slot }}
    </main>
</body>
</html>
  1. Route
<?php
// web.php

use Illuminate\Support\Facades\Route;
use Livewire\Volt\Volt;

Route::prefix('admin')->name('admin.')->group(function () {
    // Livewire Volt full-page-component
    Volt::route('/users', 'admin.users.index')->name('users.index');
});
  1. Component
<?php
// resources/views/livewire/admin/users/index.blade.php

use App\Models\User;
use Illuminate\View\View;
use Livewire\Volt\Component;

new class extends Component
{
    public function rendering(View $view): View
    {
        info('test');           // fired two times, see laravel.log
        $users = User::all();   // fired two times, Laravel Debugbar show two query

        return $view
            ->with([
                'users' => $users,
            ])
            ->layoutData([
                'pageTitle' => 'Admin Dashboard',
                'pageDescription' => 'This is description',
                'pageKeywords' => 'This is keywords',
            ]);
    }
};
?>

<div>
    @foreach ($users as $user)
        ...
    @endforeach
</div>

Problem with namespace

Volt Version

Latest

Laravel Version

10

PHP Version

8.2

Database Driver & Version

MySQL

Description

There is a problem with. the namespace, when calling artisan command VOLT::INSTALL it automaticaly creates views folder called livewire but, what if in my livewire config I have modified it?

Thanks to make custom volt config file.

Steps To Reproduce

Install the package manually and change livewire's view namespace.

Alpine not working outside volt

Volt Version

1.0.0

Laravel Version

1.0.4.1

PHP Version

8.1.2

Database Driver & Version

sqlite 2.8.17 ubuntu

Description

I just started tried using volt with a existing application, which includes a header with a modal written in alpine.

When using volt, the header didnt work anymore for some reason, but as soon as i cleared the @Volt directives, it worked just fine.

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="preconnect" href="https://fonts.googleapis.com">
	<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

	@vite(['resources/css
[Screencast from 29-07-23 13:27:31.webm](https://github.com/livewire/volt/assets/120563991/f409d66e-ffe7-4554-aa16-4a67a09e176c)
/app.css', 'resources/js/app.js'])
	<title>{{ $title ?? 'Page Title' }}</title>
</head>
	<body>
		<x-nav.header />
		<main class="pt-3">
			{{ $slot }}
		</main>
	</body>
</html>
	x-data="{
		open: false,
		toggle() {
			if (this.open) {
				return this.close()
			}
[Screencast from 29-07-23 13:27:31.webm](https://github.com/livewire/volt/assets/120563991/cecd2eb0-ec4c-4440-8f29-c90a9caa6d1f)


			this.$refs.button.focus();
			this.open = true
		},
		close(focusAfter) {
			if (! this.open) return;

			this.open = false;
			focusAfter && focusAfter.focus()
		}
	}"
	x-on:keydown.escape.prevent.stop="close($refs.button)"
	x-on:focusin.window="! $refs.panel.contains($event.target) && close()"
	x-id="['dropdown-button']"
	class="relative"
>
	<button
		x-ref="button"
		x-on:click="toggle()"
		:aria-expanded="open"
		:aria-controls="$id('dropwown-button')"
		type="button"
	>
		{{ $button }}
	</button>

	<div
		x-ref="panel"
		x-show="open"
		@click.outside="close($refs.button)"
		x-transition.origin.top
		:id="$id('dropdown-button')"
		class="absolute right-0 mt-2 w-40 rounded-md bg-white shadow-md"
	>
		<a href="/dashboard" wire:navigate class="flex items-center gap-2 w-full px-3 py-1.5 text-sm hover:bg-gray-100">
			Dashboard
		</a>
		<a href="/settings" wire:navigate class="flex items-center gap-2 w-full px-3 py-1.5 text-sm hover:bg-gray-100">
			Settings
		</a>
		<hr class="divide-y my-1">
		<form action="{{ route('auth.logout') }}" method="POST">
			@csrf
[Screencast from 29-07-23 13:27:31.webm](https://github.com/livewire/volt/assets/120563991/34fe1ce3-3b0e-43d2-89f3-48bcb359b0f3)

			<button type="submit"
					class="flex items-center gap-2 w-full px-3 py-1.5 text-sm text-red-500 hover:bg-gray-100">
				Logout
			</button>
		</form>
	</div>
</div>```

### Steps To Reproduce

Ubuntu 22.04.2 LTS

Install Laravel Folio
Install Livewire 3 
Install Laravel Volt

Laravel Echo Notifications

Volt Version

1.0.0

Laravel Version

10.10

PHP Version

8.1

Database Driver & Version

MySql 8.0 Sail

Description

Is it possible to use echo notifications in the listeners?
Not sure what to do. All of these codes are not subscribing.

Thanks.

<?php

use function Livewire\Volt\{state, on};

on([
    'echo-private:App.Models.User.1,notification' => function () {
        
    },
]);

on([
    'echo-notification:App.Models.User.1,FriendRequestSent' => function () {
    },
]);

?>

Steps To Reproduce

No detailed steps all is working on my end except for this.

[Docs]: Develop Livewire package with Volt

Currently there is no direction about how to develop a package using Volt component. Is it possible?

Using regular Livewire component it works.

<livewire:some-component />

image

And about Volt?

Folio and multiple @volt ?

Volt Version

v1.0.0-beta.4

Folio Version

v1.0.0-beta.4

Laravel Version

10.16.1

PHP Version

8.2.8

Database Driver & Version

None

Description

Is Folio supposed to work with multiples instances of @volt in same file?

Steps To Reproduce

  • Install folio + volt

  • Create on views/pages/index.blade.php

<?php

use Livewire\Volt\Component;

new class extends Component
{
    public $count = 0;
}; ?>


<div>
    <h1>Hi!</h1>

    @volt('example-1')
        <div>1</div>
    @endvolt

    <h1>Hello!</h1>
    
    @volt('example-2')
        <div>2</div>
    @endvolt

</div>
  • It renders twice same volt
image

Using `mount` method from trait in Volt component

Was advised to repost this from livewire/livewire#6158, not sure if it counts as a feature request or a bug:

I'm using a trait in a Volt component and I'd like to define a mount method in that trait that will be used by all components that implement it, rather than defining it for every component with the mount function. However at the moment the trait's mount method is not being called, even though I'm not using Volt's mount function.

This may also apply to other lifecycle methods, I've not tested those.

Volt Route Bug

Volt Version

1.6.0

Laravel Version

10.34.2

PHP Version

8.2.13

Database Driver & Version

Sail with PSQL

Description

page.blade.php

<?php

use function Livewire\Volt\{layout, state, title, mount};

layout("components.layouts.guest");

mount(function (\App\Models\Page $page){
    dd($page->slug);
});

routes/web.php

Volt::route('/{page:slug}', 'page');

Error

Illuminate \ Database \ QueryException

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "test-page" CONTEXT: unnamed portal parameter $1 = '...'
SELECT * FROM "pages" WHERE "id" = test-page limit 1

Duplicate use class lines when template comes before Volt methods

Volt Version

1.0.0

Laravel Version

10.20.0

PHP Version

8.2.9

Database Driver & Version

No response

Description

When placing your template before the Volt methods any use class lines get duplicated, resulting in "name is already in use" errors. It works fine if the template comes after the Volt methods.

Steps To Reproduce

With this component:

<div>
    // my template
</div>

<?php
use App\Concerns\Form;
use function Livewire\Volt\{uses};

uses(Form::class);

This is the compiled PHP:

<?php

use App\Concerns\Form;

?>

<div>
    // my template
</div>

<?php
use App\Concerns\Form;
use function Livewire\Volt\{uses};

uses(Form::class); ?>

Support for Volt components in non-default locations

I'm working on a private, custom package and I'd like to be able to ship a Volt component in the package.

I can use Livewire\Volt\MountedDirectories->mount() to add my local views/livewire directory but since mount() uses View::replaceNamespace() there is no persistent way to tell Volt about my views directory.

Can the code use View::addNamespace() instead or provide some other means of adding additional directories to be used when looking for a Volt view file?

Class based Volt components error

Volt Version

1

Laravel Version

10

PHP Version

8.1

Database Driver & Version

mysql winsows 10

Description

this code:

{{ $name }}

returns:
Call to undefined function Livewire\Volt\opcache_invalidate()

Steps To Reproduce

{{ $name }}

Filenames with hyphens "-"

Volt Version

1.6

Laravel Version

10.10

PHP Version

8.3.1

Database Driver & Version

No response

Description

I do not know if this has already been mentioned however I struggled getting my volt component to work, my file name "location-picker" seemed to be the cause. My methods were not recognized and neither were some other features I was expecting to work. Also I was any to use props within my component.

I do not see any mention of this in the docs about filenames not supposed to have hyphens.

Steps To Reproduce

Create a simple volt component with a hyphen in its name. eg. "example-picker.blade.php"
Create some state values and methods.
Try accessing them from the view.
Try displaying the value of any one of the components props.

The "with" function may only be invoked once per component.

Volt Version

1.0

Laravel Version

10.21.0

PHP Version

8.2.4

Database Driver & Version

8.0.30

Description

I am using Laravel + Folio + Volt.

i notice that whenever i use with on multiple pages (generated by folio), an error occured which seems like i use the same component. However i am using 2 different pages. I didn't even use wire:navigate or anything. Just normal redirect.

I don't know for sure if this is desired behavior of volt or a bug. Since to me, using folio is the same as traditional web navigation and also means different pages which should be also different component as well.

Steps To Reproduce

  1. Install fresh laravel
  2. Composer require & install Livewire, Volt & Folio
  3. Create 2 folio pages, such as php artisan make:folio employer/index and php artisan make:folio employee/index
  4. Add these code on both pages
    use function Livewire\Volt\{with}; with(fn() => [ 'testdata' => Testdata::all() ]);
  5. The error will show The "with" function may only be invoked once per component.

Volt component syntax for plain anonymous Blade components

Hello,

I really like Laravel Volt and its way to declare components and markup directly together. What I am missing now is a way to also apply this syntax to plain Blade components. It would be nice to also have this option.

After some consideration I think this should also live in this package as it is responsible for the “new” way to declare components.
So my idea would be to add it to anonymous components. If you are generally interested I can

  1. write a RFC-like proposal so that the idea can be evaluated further if requested
  2. also contribute this feature

Thank you in advance for your consideration.

`Volt::mount()` merges duplicate paths [Memory leak]

Volt Version

1.6.2

Laravel Version

10

PHP Version

8.3

Database Driver & Version

No response

Description

Volt::mount() merges new mounted directory instances regardless of path. This can lead to memory leaks, especially on Octane.

$this->paths = array_merge($this->paths, $paths->all());

for ($i = 1; $i <= 50; $i++) {
    Volt::mount([
        config('livewire.view_path', resource_path('views/livewire')),
        resource_path('views/pages'),
    ]);
}

dump(\Livewire\Volt\Volt::paths()) 

//0 => 
// Livewire\Volt..\MountedDirectory {#1715 ▶}
//  1 => 
// Livewire\Volt..\MountedDirectory {#1716 ▶}
//  2 =>  
// Livewire\Volt..\MountedDirectory {#1717 ▶}
//  3 => 
// Livewire\Volt..\MountedDirectory {#1718 ▶}
//  4 =>  
// Livewire\Volt..\MountedDirectory {#1719 ▶}
//..
//  25 => 
// Livewire\Volt..\MountedDirectory {#1979 ▶}

Steps To Reproduce

https://github.com/inmanturbo/volt-memory-leak

The `assertSessionHas()` does not work with flash messages.

Volt Version

1.3.2

Laravel Version

10.23

PHP Version

8.2

Database Driver & Version

No response

Description

The assertSessionHas() does not work with flash messages.

Steps To Reproduce

Volt component

<?php

use Livewire\Volt\Component;

new class extends Component
{
    public function save()
    {
        session()->flash('message', 'ops!');
    }
}; ?>

<div>
    volt abc
</div>

Test

Volt::test('mycomponent')
            ->call('save')
            ->assertSessionHas('message', 'ops!');

Fail

image

Title for class based API

I see it is possible to set “title” for functional API.

But I can’t find on docs how to to set a title for a class based API volt full page component.

Is that possible ?

Motivation: SEO

Including top-level PHP classes throws error "The use statement with non-compound name 'xxxx' has no effect".

Volt Version

v1.3.3

Laravel Version

v10.27.0

PHP Version

8.2

Database Driver & Version

Postgres 14

Description

When including a top-level PHP class, such as Closure, Volt components throw an error when accessed in the browser

[previous exception] [object] (ErrorException(code: 0): The use statement with non-compound name 'Closure' has no effect at /var/www/html/storage/framework/views/3c9d0dc3427d271816d9e74b3882f6e6.php:11)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(254): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /var/www/html/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(37): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/html/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(37): include('...')
#3 /var/www/html/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(38): App\\Bases\\CustomReport@anonymous->Livewire\\Mechanisms\\ExtendBlade\\{closure}()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(72): Livewire\\Mechanisms\\ExtendBlade\\ExtendedCompilerEngine->evaluatePath()
#5 /var/www/html/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(16): Illuminate\\View\\Engines\\CompilerEngine->get()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(195): Livewire\\Mechanisms\\ExtendBlade\\ExtendedCompilerEngine->get()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(178): Illuminate\\View\\View->getContents()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/View/View.php(147): Illuminate\\View\\View->renderContents()
#9 /var/www/html/vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php(245): Illuminate\\View\\View->render()
#10 /var/www/html/vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php(289): Livewire\\Mechanisms\\HandleComponents\\HandleComponents->Livewire\\Mechanisms\\HandleComponents\\{closure}()
#11 /var/www/html/vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php(235): Livewire\\Mechanisms\\HandleComponents\\HandleComponents->trackInRenderStack()
#12 /var/www/html/vendor/livewire/livewire/src/Mechanisms/HandleComponents/HandleComponents.php(61): Livewire\\Mechanisms\\HandleComponents\\HandleComponents->render()
#13 /var/www/html/vendor/livewire/livewire/src/LivewireManager.php(72): Livewire\\Mechanisms\\HandleComponents\\HandleComponents->mount()
#14 /var/www/html/vendor/livewire/volt/src/LivewireManager.php(22): Livewire\\LivewireManager->mount()
#15 /var/www/html/vendor/livewire/livewire/src/Features/SupportPageComponents/HandlesPageComponents.php(17): Livewire\\Volt\\LivewireManager->mount()
#16 /var/www/html/vendor/livewire/livewire/src/Features/SupportPageComponents/SupportPageComponents.php(115): Livewire\\Component->Livewire\\Features\\SupportPageComponents\\{closure}()
#17 /var/www/html/vendor/livewire/livewire/src/Features/SupportPageComponents/HandlesPageComponents.php(14): Livewire\\Features\\SupportPageComponents\\SupportPageComponents::interceptTheRenderOfTheComponentAndRetreiveTheLayoutConfiguration()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Livewire\\Component->__invoke()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call()
#23 /var/www/html/vendor/livewire/volt/src/VoltManager.php(37): Illuminate\\Container\\Container->call()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/CallableDispatcher.php(40): Livewire\\Volt\\VoltManager->Livewire\\Volt\\{closure}()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(237): Illuminate\\Routing\\CallableDispatcher->dispatch()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(208): Illuminate\\Routing\\Route->runCallable()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\\Routing\\Route->run()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#32 /var/www/html/app/Http/Middleware/AuthenticateEmployees.php(16): Illuminate\\Auth\\Middleware\\Authenticate->handle()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\\Http\\Middleware\\AuthenticateEmployees->handle()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Session\\Middleware\\StartSession->handle()
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#43 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\\Pipeline\\Pipeline->then()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(777): Illuminate\\Routing\\Router->runRouteWithinStack()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(741): Illuminate\\Routing\\Router->runRoute()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(730): Illuminate\\Routing\\Router->dispatchToRoute()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch()
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#52 /var/www/html/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#53 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#54 /var/www/html/vendor/genealabs/laravel-governor/src/Http/Middleware/ParseCustomPolicyActions.php(23): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): GeneaLabs\\LaravelGovernor\\Http\\Middleware\\ParseCustomPolicyActions->handle()
#56 /var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(66): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#58 /var/www/html/vendor/genealabs/laravel-casts/src/Http/Middleware/AssetInjection.php(10): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): GeneaLabs\\LaravelCasts\\Http\\Middleware\\AssetInjection->handle()
#60 /var/www/html/app/Http/Middleware/SetScopesForClientCredentialsToken.php(34): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\\Http\\Middleware\\SetScopesForClientCredentialsToken->handle()
#62 /var/www/html/app/Http/Middleware/SecureHeaders.php(16): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): App\\Http\\Middleware\\SecureHeaders->handle()
#64 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#65 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#66 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#67 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#68 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#69 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#70 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#71 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#72 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#73 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#74 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#75 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\HandleCors->handle()
#76 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#77 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#78 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#79 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then()
#80 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#81 /var/www/html/public/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle()
#82 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('...')
#83 {main}
"} 

Steps To Reproduce

The following component example should reproduce the error:

<?php

use Closure;
use Livewire\Volt\Component;

new class extends Component {
    //

    public function test(): Closure
    {
        return function () {
            echo "Hello World";
        };
    }
}; ?>

<div>
    Hello World
</div>

Path cannot be empty error when creating anonymous volt component

Volt Version

1.0.0-beta.1

Laravel Version

10.16.1

PHP Version

8.2.1

Database Driver & Version

MySQL 8.0.30

Description

Getting error "Path cannot be empty" when i try to create an anonymous volt component inside folio page
image
image

Steps To Reproduce

Install Laravel Folio, Livewire v3, Laravel Volt
Delete default route
Create a page with php artisan make:folio index
Add the following code

<?php

use function Livewire\Volt\{state};

state(['count' => 0]);
$increment = fn() => $this->count++;
?>
<div>
  index page
  @volt('counter')
    <div>
	    <p>{{$count}}</p>
	    <button wire:click="increment">+</button>
    </div>
  @endvolt
</div>

Try to load the folio route with the browser

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.