Merge Multiple Collection Paginate in Laravel Example
In this post we will give you information about Merge Multiple Collection Paginate in Laravel Example. Hear we will give you detail about Merge Multiple Collection Paginate in Laravel ExampleAnd how to use it also give you demo for it if it is necessary.
If you are merge multiple laravel collection and you need to paginate with laravel collection then i will show you how to paginate a merged collection in laravel 5.8 application. you can easily make pagination of multiple merge collection in laravel 5.
We will create ‘paginate’ function using Collection macro method. You need to register that method to AppServiceProvider. i will give you very simple example to understand how it is working for laravel paginate collection or array.
Laravel 5 - Class 'Input' not found issue?
In this post we will give you information about Laravel 5 - Class 'Input' not found issue?. Hear we will give you detail about Laravel 5 - Class 'Input' not found issue?And how to use it also give you demo for it if it is necessary.
When i start to work on Laravel 5.2 at that time i fetch this problem "Class 'Input' not found". When i copy my old controller code from laravel 5.1 version that time i found this issue, but i also could use Input insted to Request but i want to use Input as it is. But at last found solution. you have to just use following aliase on your controller.
use IlluminateSupportFacadesInput as Input
Hope this code and post will helped you for implement Laravel 5 - Class 'Input' not found issue?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
So, basically you can make manually pagination with laravel collection. let’s see bellow example:
web/routes.php
Route::get('collection-array', function(){
$user = AppUser::get();
$product = AppProduct::get();
$data = $user->merge($product)->paginate(10);
dd($data);
});
Now you need to register collection paginate method on AppServiceProvider file.
app/Providers/AppServiceProvider.php
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportCollection;
use IlluminatePaginationLengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
/**
* Paginate a standard Laravel Collection.
*
* @param int $perPage
* @param int $total
* @param int $page
* @param string $pageName
* @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,
]
);
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
}
}
Now you can check it…
I hope it can work…
Hope this code and post will helped you for implement Merge Multiple Collection Paginate in Laravel Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs