Skip to content

Instantly share code, notes, and snippets.

@manjufy
Last active December 25, 2016 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manjufy/86a4536a62c4c915ca81810d02bd6b99 to your computer and use it in GitHub Desktop.
Save manjufy/86a4536a62c4c915ca81810d02bd6b99 to your computer and use it in GitHub Desktop.
Laravel snippets (5.3)

Pagination

Laravel pagination is integrated with query builder and Eloquent ORM

Paginating Query Builder Results

Example: In Controller / Model

 $articles = DB::table('article')->paginate(10);
   return view('article.index', ['articles' => $article]);

And in the View file

<div class="container">
  @foreach ($articles as $article)
      {{ $article->name }}
  @endforeach
</div>
{{ $articles->links() }}

Paginating Eloquent Results

$articles = Article::paginate(10); // OR
$articles = Article::where('status', 'active')->paginate(10); // Or
// Simple paginate
$articles = Article::where('status','active')->simplePaginate(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment