使用laravel 實現分頁效果 超簡單
阿新 • • 發佈:2018-12-11
每頁展示5條資料
控制器
class indexCo extends Controller
{
public function cc () {
$lists = UserAli:: orderBy('user_id','desc') -> paginate(5);
return view('cc',compact('lists'));
}
}
layout/main.blade.php
<!DOCTYPE html> <html> <head> <title>Home</title> <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css"> </head> <body> <h1>Home</h1> <p>Welcome to My web</p> </body> </html> <!DOCTYPE html> <html> <head> <title>About</title> </head> <body> <h1>About</h1> <p>This is my first Laravel web</p> @yield("content") </body> </html>
cc模板
view/cc.blade.php
@extends('layout.main') @section("content") <div> @foreach($lists as $value) <div> 阿里賬號是:{{$value -> source}} <time>{{$value -> add_time}}</time> </div> @endforeach </div> {{$lists -> links()}} @endsection
兩句話搞定分頁。
當然,blade模板需要引入bootstrap,否則樣式是出不來的。
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">