Giter Club home page Giter Club logo

laravel-item-paginate's Introduction

Laravel Item Paginator

Paginate based on last item, not page.

Build Status StyleCI Codacy Badge Codacy Badge

Installation

composer require askedio/laravel-item-paginate

Add the following trait to your Models.

use \Askedio\ItemPaginator\ItemPaginatorTrait;

Add the following provider to config/app.php

\Askedio\ItemPaginator\ItemPaginatorServiceProvider::class,

Usage

This package is based off simplePaginate and will take the same parameters.

$users = new User();

$paginated = $users->itemPaginate();

dd($paginated);

The last parameter is the field that will be used to paginate by, defaults to id.

itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)

ORDER BY DESC

If you want to decend your sorting you'll want to use itemPaginateDesc instead of itemPaginate. The first page will add an extra query to find the last item.

Example Output

array:6 [
  "limit" => 2
  "next_page_url" => "http://localhost?from=190"
  "from" => 100
  "to" => 190
  "data" => array:2 [
    0 => array:8 [
      "id" => 100
      "name" => "test"
      "email" => "[email protected]"
      "password" => "test"
      "remember_token" => null
      "created_at" => "2016-08-02 18:13:19"
      "updated_at" => "2016-08-02 18:13:19"
      "deleted_at" => null
    ]
    1 => array:8 [
      "id" => 190
      "name" => "test2"
      "email" => "[email protected]"
      "password" => "test"
      "remember_token" => null
      "created_at" => "2016-08-02 18:13:19"
      "updated_at" => "2016-08-02 18:13:19"
      "deleted_at" => null
    ]
  ]
]

Disclaimer

Will only sort by incremental ids.

I've only tested this with sqlite and mysql (see tests) so it may not work in every situation. Please report any you find.

laravel-item-paginate's People

Contributors

gcphost avatar

Watchers

James Cloos avatar M Amir Shahzad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.