Laravel 5.8 Merge Multiple Collection Paginate

Today, We want to share with you Laravel 5.8 Merge Multiple Collection Paginate.In this post we will show you laravel resource collection pagination, hear for Merge Multiple Collection Paginate in Laravel Example we will give you demo and example for implement.In this post, we will learn about laravel merge two collections with an example.

Laravel 5.8 Merge Multiple Collection Paginate

There are the Following The simple About Laravel 5.8 Merge Multiple Collection Paginate Full Information With Example and source code.

As I will cover this Post with live Working example to develop merge multiple collections laravel 5.8, so the some laravel 5.7, 5.8 paginate collection for this example is following below.

Read Also:  how to create model in laravel (With Example)?

Merge multiple collections laravel 5.8

web/routes.php

Route::get('collection-array', function(){
	$member = \App\Member::get();
	$student = \App\Student::get();
	$data = $member->merge($student)->paginate(10);
	dd($data);
});

After that, simple We need to register a ServiceProvider Like a collection paginate method on AppServiceProvider main file.

app/Providers/AppServiceProvider.php

<?php
 
//Laravel Include namespace 
namespace App\Providers;
   
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
    
class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        /**
         * Paginate a standard Laravel Collection.
         * www.pakainfo.com
         * @param int $perPage display row
         * @param int $total all records
         * @param int $page all pages
         * @param string $pageName your live page name
         * @return array
         */
        Collection::macro('paginate', function($perPage, $total = null, $page = null, $pageName = 'page') {
            $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
            return new LengthAwarePaginator(
                $this->forPage($page, $perPage),
                $total ?: $this->count(),
                $perPage,
                $page,
                [
                    'path' => LengthAwarePaginator::resolveCurrentPath(),
                    'pageName' => $pageName,
                ]
            );
        });
    }

    public function boot()
    {
             
    }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  How to Get Yii last inserted ID from database

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.


I hope you get an idea about Laravel 5.8 Merge Multiple Collection Paginate.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.