Language

How To implement pagination in Laravel 5.4 with example

Date 12 Aug, 2017

Details :

1. In laravel you can easily implement pagination use following way

In Controller:

public function postlist()
   {
            $tagdata1=DB::table('posts')->where('tag','laravel')->paginate(10);
            $tagdata=json_decode( json_encode($tagdata1), true); 
            
            return view('FrontEnd.tags')->with(['tagdata'=>$tagdata,'tagdata1'=>$tagdata1]);
  }

In View:

Note: In view you got all data in inside data array see below. use $tagdata1 to render pagination that have values in object form. $tagdata have values in array form

    <?php foreach ($tagdata['data'] as $value) { ?>
        <div class="grid">
           <h2>{{$value['title']}}</h2>
                <div class="price-details">
                   <div class="price-number">
                         <p>{{date('d M, Y', strtotime($value['created_at']))}}</p>
                   </div>           
                </div>
         <?php } ?>
       </div>
      {{$tagdata1->render()}}