PHP code example of aneeskhan47 / laravel-pagination-merge
1. Go to this page and download the library: Download aneeskhan47/laravel-pagination-merge 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/ */
aneeskhan47 / laravel-pagination-merge example snippets
use App\Models\Post;
use App\Models\Event;
use Aneeskhan47\PaginationMerge\Facades\PaginationMerge;
class PublicationsController extends Controller
{
/**
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$events = Event::latest()->paginate(5);
$posts = Post::latest()->paginate(5);
$publications = PaginationMerge::merge($events, $posts)
->sortByDesc('created_at')
->get();
// since get() will return \Illuminate\Pagination\LengthAwarePaginator
// you can continue using paginator methods like these etc:
$publications->withPath('/admin/users')
->appends(['sort' => 'votes'])
->withQueryString()
->fragment('users')
->setPageName('publications_page');
return view('publications.index', compact('publications'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.