So verwenden Sie die Pagination in Laravel LiveWire mit der funktionalen Version, nicht der KlassePhp

PHP-Programmierer chatten hier
Guest
 So verwenden Sie die Pagination in Laravel LiveWire mit der funktionalen Version, nicht der Klasse

Post by Guest »

Ich versuche nur, dem Bootcamp für Laravel mit LiveWire zu folgen: https://bootcamp.laravel.com/livewire/showing-chirps >
Rückgabe aller Chirps gleichzeitig wird die Produktion nicht skaliert. Schauen Sie sich die leistungsstarke Pagination von
Laravel an, um die Leistung zu verbessern. />
< /code>


@foreach ($chirps as $chirp)


...

@endforeach



< /code>
Reading the documentation it only include examples for the "class version" https://livewire.laravel.com/docs/pagin ... asic-usage like:
use Livewire\WithPagination;
use Livewire\Volt\Component;
use App\Models\Post;

new class extends Component {
use WithPagination;

public function with(): array
{
return [
'posts' => Post::paginate(10),
];
}
}
< /code>
So I already tried importing the trait in the view like:
use Livewire\WithPagination;

$getChirps = fn () => $this->chirps = Chirp::paginate(10);
< /code>
or
$getChirps = function () {
return $this->chirps = Chirp::with('user')->paginate(15);
};
< /code>
And I'm getting the next error:

Property type not supported in Livewire for property:
[{"current_page":1,"data":[{"id":1,"user_id":1,"message":"This chirp
is a
test","created_at":"2025-02-14T03:24:24.000000Z","updated_at":"2025-02-14T03:24:24.000000Z","user":{"id":1,"name":"Roberto","email":"robertohdll@gmail.com","email_verified_at":null,"created_at":"2025-02-09T14:10:52.000000Z","updated_at":"2025-02-09T14:10:52.000000Z"}}],"first_page_url":"http://127.0.0.1:8000/chirps?page=1","f ... =1","links":[{"url":null,"label":"«
Previous","active":false},{"url":"http://127.0.0.1:8000/chirps?page=1","l ... bel":"Next
»","active":false}],"next_page_url":null,"path":"http://127.0.0.1:8000/chirps","per_page ... ,"total":1}]

So the query to the DB is working and is getting the pages, but the error is something else, I already tried to find any specific example for the pagination in the functional version but don't have any luck.
Could be great if somebody can help me to understand how to fix this Property type not supported message, or understand if is not possible to use the pagination with the Functional version.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post