1.直接上代码
控制器
public function page(Request $request){
//总条数
$num=DB::table('mon_message')->count();
//每页显示
$shownum=4;
$page=ceil($num/$shownum);
$pageshow=$request['page']? $request['page'] :1;
$offset=($pageshow-1)*$shownum;
$prev=$pageshow-1<1? 1: $pageshow-1;
$next=$pageshow+1>=$page? $page :$pageshow+1;
$data=DB::table('mon_message')
->offset($offset)
->limit($shownum)
->orderBy('id','asc')
->get();
return view('page',compact('data','prev','next','page'));
}
2.视图
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<ul class="pagination">
<li><a href="{{url('page')}}/list_1.html">首页</a></li>
<li><a href="{{url('page')}}/list_{{$prev}}.html">上一页</a></li>
@for($i=1;$i<=$page;$i++)
<li><a href="{{url('page')}}/list_{{$i}}.html">{{$i}}</a></li>
@endfor
<li><a href="{{url('page')}}/list_{{$next}}.html">下一页</a></li>
<li><a href="{{url('page')}}/list_{{$page}}.html">尾页</a></li>
</ul>
</center>
<center>
@foreach($data as $k=>$v)
<div class="col-md-6" style="border: 2px solid deeppink;margin-top: 20px" id="{{$v->id}}">
<div class="row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div class="col p-4 d-flex flex-column position-static">
<strong class="d-inline-block mb-2 text-success">{{$v->id}}</strong>
<a href="{{url('infomess')}}/{{$v->id}}"><h3 class="mb-0">{{$v->title}}</h3></a>
<div class="mb-1 text-muted">{{$v->author}}</div>
<p class="mb-auto">{{$v->talk}}</p>
<a href="#" class="stretched-link"><img src="{{$v->img}}" style="width: 100%;height: 200px"></a>
</div>
</div>
<a href="{{url('info')}}/{{$v->id}}" class="btn btn-primary">详情</a>
<input type="button" value="删除" class="btn btn-danger" onclick="fun({{$v->id}})">
<a href="{{url('up')}}/{{$v->id}}" class="btn btn-warning">修改</a>
</div>
{{-- <img src="{{$v->img}}" alt="">--}}
@endforeach
</center>
</body>
</html>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
function fun(id) {
$.get("http://www.web5mon.com/del/"+id,function (status,data) {
$('#'+id).remove();
})
}
</script>