0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel Paginate

Last updated at Posted at 2020-03-26

##ページネーションメソッドを使ってページャの実装

HogeController.php
	use App\Models\Hoge; #Hogeモデルがある前提

    $hoges = Hoge::paginate(5);
    return view('hoge.index', ['hoges' => $hoges]);
style.scss
  .page ul li{
    display: inline;
  }
hoge/index.blade.php
  @foreach($hoges as $hoge)
    <tr>
      <td>{{ $hoge->id }}</td>
      <td>{{ $hoge->name }}</td>
      <td>{{ $hoge->email }}</td>
      <td>{{ $hoge->age }}</td>
    </tr>
  @endforeach

<div class="page">
    {{ $hoges->links() }}
</div>

1.コントローラでpaginateメソッドを使って表示件数を指定
2.viewでlinksメソッドでページャを表示

##orderByを使ってソート

#上記の例にorderByメソッドを追加するだけ
Hoge::orderBy('age', 'desc')->paginate(5);

##参考URL

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?