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.

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.

Leave a Comment