2015-06-25 163 views

回答

1

與這一個

//in controller 
$users = \App\User::paginate(15) 
    return view('your desired view file name', compact('users')); 


// in view 
     <div class="text-center text-muted" role="status" aria-live="polite">Showing {{$users->firstItem()}} to {{$users->lastItem()}} of {{$users->total()}} entries</div> 
     <div style="display:flex;justify-content:center;align-items:center;" > 
      <p></p> 
      {!! with(new Illuminate\Pagination\BootstrapThreePresenter($users))->render()!!} 
     </div> 
0

在控制器你somrthing像下面

$users = \App\User::paginate(15) 
    return view('template.file', compact('users')); 

並在查看文件中,您輸入以下內容

<table> 
    <thead> 
     <tr> 
      <th>Name</th> 
     </tr> 
    </thead> 
    <tbody> 
     @foreach ($users as $user) 
     <tr> 
      <td> {{ $user->name }} </td> 
     </tr> 
     @endforeach 
    </tbody> 
</table> 
{!! $users->appends(\Input::except('page'))->render() !!} 

最後一行呈現分頁鏈接。

+0

laravel錯誤嘗試--Call未定義的方法照亮\數據庫\雄辯\收藏:: PAGINATE() –

+0

我已經更新我的答案。抱歉,我犯了一個小錯誤。 'all()'返回collection和collection類沒有paginate方法。你只需要'App/User :: paginate(15)' –