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

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

반응형

안녕하세요 상훈입니다.

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

먼저, 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

@foreach($posts as $post) {{ $post->title }} {{ $post->description }} @endforeach {{ $posts->links() }}

결과물

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

반응형

from http://code-hoon.tistory.com/67 by ccl(A) rewrite - 2021-10-03 20:01:07