Laravel pagination using mysql limit offset

Laravel 7.2 routing with route group auth guard check with prefix

Laravel pagination using mysql limit offset

Hello to all, welcome to In this post, i will tell you, Laravel pagination using mysql limit offset.

Laravel is the top mvc framework in php.

Here is working and tested code for Laravel pagination using mysql limit offset:
// Paginate
$limit = 2;

//$_GET['page'] - get page number form url like -

$offset = (null !== $_GET['page']) ? ($_GET['page'] == 1) ? 0 : ($_GET['page']-1) * $limit : 0;

$raw_sql = 'SELECT * FROM user';

//get total number of pages divided by limit
$total_pages = sizeof(DB::select(DB::raw($raw_sql))) / $limit;

$query = 'SELECT * FROM user LIMIT '.$limit.' OFFSET '.$offset;

$user = DB::select(DB::raw($query));


 If you have any query related to this post, then feel free to ask. the rich post


Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.