Пагинация.
Откроем
\app\Http\Controllers\User\HomeController.php
public function index() {
$posts = post::where('status', 1)->paginate(2);
return view('user.blog', compact('posts'));
}
$posts = post::where('status', 1)->paginate(2);
return view('user.blog', compact('posts'));
}
Откроем
\resources\views\user\blog.blade.php
@extends('user/app')
@section('bg-img',
asset('user/img/home-bg.jpg'))
@section('title',
'Bitfumes blog')
@section('sub-heading',
'Learn together and grow together')
@section('main-content')
    <!-- Main
Content -->
    <div
class="container">
        <div
class="row">
            <div
class="col-lg-8 col-md-10 mx-auto">
               
<div class="post-preview">
                  
 @foreach ($posts as $post)                
                  
 <a href="{{ route('post', $post->slug) }}">
                  
 <h2 class="post-title">
                  
     {{ $post->title }}
                  
 </h2>
                  
 <h3 class="post-subtitle">
                  
     {{ $post->subtitle }}
                  
 </h3>
                  
 </a>
                  
 <p class="post-meta">Posted by <a href="#">Start
Bootstrap</a> {{ $post->created_at->diffForHumans()
}}</p>
                  
 @endforeach 
               
</div>
                  
 <hr>
               
<!-- Pager -->
               
<div class="clearfix">
                  
 <ul class="pager">
                  
     <li class="next">
                  
         {{ $posts->links() }}
                  
     </li>
                  
 </ul>  
               
</div>
            </div>
        </div>
    </div>
    <hr>
@endsection
 
Комментариев нет:
Отправить комментарий