PHP code example of austinw / laravel-union-paginator
1. Go to this page and download the library: Download austinw/laravel-union-paginator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
austinw / laravel-union-paginator example snippets
use AustinW\UnionPaginator\UnionPaginator;
$feed = UnionPaginator::forModels([Post::class, Comment::class])
->latest()
->paginate(20);
foreach ($feed as $item) {
// $item is a Post or a Comment model, newest first.
}
$paginator->paginate(15); // LengthAwarePaginator, with a total
$paginator->simplePaginate(15); // next/previous only, skips the COUNT over the union
$paginator->cursorPaginate(15); // cursor pagination for large or infinite feeds
$paginator
->setSelectedColumns(Post::class, ['posts.id as id', 'posts.published_at as created_at', 'posts.title as title'])
->setSelectedColumns(Comment::class, ['comments.id as id', 'comments.created_at', 'comments.body as title']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.