Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Pagination in Laravel 5.x

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    It is very painful to use pagination in other framework but In Laravel 5.x it is very easy to implement pagination. By using paginate method on the query builder we will takes care of setting the proper limit and offset based on the current page being viewed by the user.

    In Paginate we will pass a single argument which will tell us the number of records we want to show per page.

    Example:

    <?php
    
    namespace App\Http\Controllers;
    
    use DB;
    use App\Http\Controllers\Controller;
    
    class UserController extends Controller
    {
        /**
         * Show all of the users for the application.
         *
         * @return Response
         */
        public function index()
        {
            $users = DB::table('users')->paginate(15);
    
            return view('user.index', ['users' => $users]);
        }
    }
    

    If you want to display simple "Next" & "Previous" then we have a option of using the simplePaginate.When we have large dataset and we dont want to see a link then we use simplePaginate

    Example:

    $users = DB::table('users')->simplePaginate(15);
    

    By this way we can implement pagination using Laravel 5.x

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: