상세 컨텐츠

본문 제목

[ Laravel ] Pagination : Paginator 라라벨 페이징 처리 하는 방법

BackEnd/PHP

by SangHoonE 2021. 10. 3. 19:35

본문

반응형

안녕하세요 상훈입니다. 

라라벨에서 게시글의 페이징 처리하는 방법에 대해 포스팅하겠습니다.

먼저, ui 설정하고, 진행하겠습니다. [ 이미 하신 분들은 건너뛰어도 무방합니다. ] 

$ composer require laravel/ui
$ php artisan ui bootstrap
$ npm install & npm run dev

 


 

1. Route
2. Controller
3. view

 

1. Route

Route::get('/', function () {
    $posts = Post::paginate(1);
    return view('home', compact('posts'));
});

 - table:posts의 데이터를 home.blade.php 경로로 보내준다고 선언합니다.

 

2. Controller

 - 컨트롤러에서는 바로 home.blade.view를 return 시켜줍니다.

 public function index()    {        
     return view('home');    
 }

 

3. View

<div class="card">
  <div class="card-body">
    @foreach($posts as $post)
      <p>{{ $post->title }}</p>
      <p>{{ $post->description }}</p>
    @endforeach
  </div>
  {{ $posts->links() }}
</div>

 

 

결과물

아무래도 bootstrap의 css를 끌어오지 못한 것 같다,,

 

 

 

 

관련글 더보기

댓글 영역