Laravel pagination


Laravel pagination : Pagination is used to display the dynamic data using links for dynamic results. In other framework you need to work more to implement pagination functionality. Laravel provides rich pagination functionality which you can use to generate pagination links quickly. We are going to explain the simple method to create pagination in laravel using the paginate method.


Laravel pagination Syntax And Example –

Lets create a simple pagination in laravel –

Here is we are going to add pagination in UsersController and added pagination on user’s view-

Laravel pagination Syntax And Example

class UsersController extends BaseController {

    public function userList()
    {
        $this->layout->title = "App Users ";
        $num = 20; // no of results you want to show on each page.
        $usersList = Users::orderby('created_at', 'desc')->paginate($num);
        $this->layout->content = View::make('content.userscontent')->with('usersList', $usersList);
    }

}

Where $num is no of results you want to show on each page.

Now lets display the pagination links on view

Laravel pagination Show Links On Views-

<?php echo $usersList->links(); ?>

Here we have displayed the links for pagination.


Advertisements

Add Comment

📖 Read More