livewire / volt

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

[1.x] Adds `with` method to the class API #31

Closed nunomaduro closed 1 year ago

nunomaduro commented 1 year ago

Addresses https://github.com/livewire/livewire/pull/6406.

This pull request adds the with method to the class API, so it can be used to render data on the view. Example:

<?php

namespace App\Livewire;

use Livewire\WithPagination;
use Livewire\Volt\Component;
use App\Models\Post;

new class extends Component
{
    use WithPagination;

    public function with()
    {
        return [
            'posts' => Post::paginate(10),
        ];
    }
}