For getting every new tutorial link Please join our telegram group

Part 16 laravel quey builder paginate() vs simplePaginate() method

In this laravel tutorial, we will discuss two types of pagination method paginate vs simple paginate in laravel 6, laravel 7 and laravel 8.

Laravel paginate vs simple paginate method.

Laravel provide two types of pagination method first is paginate method which is useful when we require next previous button and page links or we also customize our pagination links.

Second pagination method is simple paginate method which is only provide next and previous links. When we require only the next and previous buttons then simplePaginate method is enough.

The only difference between paginate vs simplePaginate method is paginate method contains more data show it takes more time in execution compare to simplePaginate, so paginate method use when requiring page links. Let an example of both types of pagination methods.

StudentController

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class StudentController extends Controller{
 public function index(){
 		//pagination method
    $students = DB::table('students')->paginate(10);

    //OR
    //simple pagination
    $students = DB::table('students')->simplePaginate(10);

    return view('students', compact('students'));
  }
}

View File students.blade.php

@foreach($students as $student)
	<p>{{ $student->id }} : {{ $student->name }}</p>
@endforeach

{{ $students->links() }}

You read this tutorial on advanced web tutorial. here we provide beginners to advanced tutorial.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Related tutorial links