2017-10-07 125 views
0

這裏是我的代碼,我展示了我的博客帖子的分頁!分頁laravel中沒有樣式5.5

<div class="clearfix"> 
    {{ $posts->render() }} 
    <a class="btn btn-secondary float-right" href="#">Older Posts &rarr;</a> 
</div> 

這裏就是分頁功能被稱爲控制器。

public function index() 
{ 
    $posts = post::where('status',1)->paginate(2); 
    return view('user.blog',compact('posts')); 
} 

我試了很多,但我的分頁顯示,但沒有正確的風格! 爲什麼?

Here I show what is happening above the black line !!

回答

1

要顯示在您的刀片鑑於分頁鏈接:

{{ $posts->links() }} 

Laravel文檔:https://laravel.com/docs/5.5/pagination

+0

我以前做過, 它'噸的工作,也沒有現在 –

+0

您使用的引導?來自Laravel的文檔:'paginator生成的HTML與Bootstrap CSS框架兼容。' – kerrin

+0

我正在使用laravel 5.5,並且boostrap與它集成了 –

0

要在引導式添加到鏈接,你可以創建你pagination.blade .php包含類似這樣的內容

@if ($paginator->hasPages()) 
    <ul class="pagination"> 
     {{-- Previous Page Link --}} 
     @if ($paginator->onFirstPage()) 
      <li class="page-item disabled"> 
       <a class="page-link" href="#" aria-label="Previous"> 
        <span aria-hidden="true">&laquo;</span> 
        <span class="sr-only">Previous</span> 
       </a> 
      </li> 
@else 
      <li class="page-item"><a href="{{ $paginator->previousPageUrl() }}" class="page-link" rel="prev">&laquo;</a></li> 
@endif 

{{-- Pagination Elements --}} 
@foreach ($elements as $element) 
{{-- "Three Dots" Separator --}} 
    @if (is_string($element)) 
      <li class="page-item disabled">{{ $element }}</li> 
    @endif 

    {{-- Array Of Links --}} 
    @if (is_array($element)) 
     @foreach ($element as $page => $url) 
       @if ($page == $paginator->currentPage()) 
         <li class="page-item active"> 
          <a href="#" class="page-link">{{ $page }}<span class="sr-only">(current)</span></a> 
         </li> 
       @else 
         <li class="page-item"> 
          <a href="{{ $url }}" class="page-link">{{ $page }}</a> 
         </li> 
       @endif 
       @endforeach 
      @endif 
     @endforeach 

     {{-- Next Page Link --}} 
     @if ($paginator->hasMorePages()) 
       <li class="page-item"><a href="{{ $paginator->nextPageUrl() }}" class="page-link" rel="next">&raquo;</a></li> 
     @else 
       <li class="page-item disabled"> 
        <a class="page-link" href="#" aria-label="Next"> 
         <span aria-hidden="true">&raquo;</span> 
         <span class="sr-only">Next</span> 
        </a> 
       </li> 
     @endif 
    </ul> 
    @endif 

,比使用

{{ $results->links('pagination') }} 
+0

已經有一種方法更短,工作的解決方案。 –