laravel 5/6/7 pagination parameters with union

Today, We want to share with you laravel 5/6/7 pagination parameters with union.In this post we will show you laravel pagination, hear for laravel pagination count we will give you demo and example for implement.In this post, we will learn about laravel pagination with search with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

laravel 5/6/7 pagination parameters with union

There are the Following The simple About laravel paginate union Full Information With Example and source code.

As I will cover this Post with live Working example to develop custom pagination in laravel 5/6/7, so the Manual Pagination with union query in laravel is used for this example is following below.

How to add pagination with union in Laravel 4 and Laravel 5 ?

Laravel is a web application framework with expressive, elegant syntax.The PHP Framework for Web Artisans,freeing you to create without sweating the small things. CRUD Operation With Server Side.

using Laravel 5

namespace App\Http\Controllers;
use Input;
use Request;
use View;
class AdminController extends Controller
{
	
	public function index()
	{
		$page = Input::get('page', 1);
		$paginate = 10;
		 
		$teachers = DB::table("teachers")
		            ->select("id", "good_name", "sirname", "email")
		            ->where("depart_id", $id);
		$data = DB::table("students")
		            ->select("id", "good_name", "sirname", "email")
		            ->where("depart_id", $id)
		            ->union($teachers)
		            ->get();
		 
		$offSet = ($page * $paginate) - $paginate;
		$itemsForCurrentPage = array_slice($data, $offSet, $paginate, true);
		$data = new \Illuminate\Pagination\LengthAwarePaginator($itemsForCurrentPage, count($data), $paginate, $page);
		 
		return View::make('index',compact('data'));
	}
}

using Laravel 4

namespace App\Http\Controllers;
use Input;
use Request;
use View;
class AdminController extends Controller
{
	
	public function index()
	{
		$page = Input::get('page', 1);
		$paginate = 10;
		$teachers = DB::table("teachers")
		            ->select("id", "good_name", "sirname", "email")
		            ->where("depart_id", $id);
		$students = DB::table("students")
		            ->select("id", "good_name", "sirname", "email")
		            ->where("depart_id", $id)
		            ->union($teachers)
		            ->get();
		$slice = array_slice($students, $paginate * ($page - 1), $paginate);
		$data = Paginator::make($slice, count($students), $paginate);
		return View::make('index',compact('data'));
	}
}

Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about Pagination with Custom Queries in Laravel.
I would like to have feedback on my infinityknow.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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   URL Redirect in Laravel Tutorial
  2.   Laravel Simple CRUD Application Script
  3.   Laravel 6 Join Multiple Tables Fetch Data
  4.   PHP Laravel 6 create Pagination Example - demo
  5.   Print last query in laravel eloquent - Examples
  6.   Email Verification in Laravel 5.7 Example Tutorial
  7.   Simple PHP Laravel Pagination script
  8.   Laravel 6 CRUD Tutorial With Example from scratch
  9.   Simple Laravel Pagination Example Tutorial
  10.   Laravel Pagination Example Tutorial