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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Simple Laravel Pagination Example Tutorial
  2.   Laravel Query Builder Join with subquery Example
  3.   How to display image from storage path using route in Laravel?
  4.   Laravel 6 Pagination Link Customizations Example
  5.   File Upload in Laravel 7 Example Tutorial
  6.   Laravel 6 Redirect Function
  7.   Laravel 7 Custom Pagination View Example Tutorial
  8.   PHP Laravel Charts and Graphs Data from Database
  9.   Laravel Custom Namespaces Example Tutorial
  10.   Laravel Pagination Example Tutorial