控制器方法代码
public function index(Request $request)
{
//明白了明白了,为什么要使用appends把参数配置上
//$request->input取得是url参数的值,把参数拼进去。再点击下一页的时候就链接跳转进入控制器处理,就可以获取到查询条件了。
//获取到文本域输入的值
$selects = $request->input('selects');
$students = Student::where('name', 'like', '%' . $selects . '%')->paginate(5);
//把$selects传入视图,当作参数条件循环使用
return view('student.index', [
'students' => $students,
'selects' => $selects
]);
}
Blade 分页处代码
{!! $students->appends(['selects' => $selects])->render() !!}
//上面代码如此简洁的代码是框架内置的好
//把上面代码打印显示结果:
<pre class="sf-dump" id="sf-dump-711558732" data-indent-pad=" " style="display: block; white-space: pre-wrap; padding: 5px; background-color: rgb(255, 255, 255); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Monaco, Consolas, monospace; word-wrap: break-word; position: relative; z-index: 100000; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><abbr title="Illuminate\Support\HtmlString" class="sf-dump-note" style="text-decoration: none; border: none; cursor: help; color: rgb(167, 29, 93);">HtmlString</abbr> {#262 ▼ <samp class="sf-dump-expanded">#html: "<ul class="pagination"><li><a href="http://www.larastudent.com:871/student/index?selects=1&page=1" rel="prev">«</a></li> <li><a href="http://www.larastudent.com:871/student/index?selects=1&page=1">1</a></li><li class="active"><span>2</span></li> <li class="disabled"><span>»</span></li></ul>"</samp> }</pre>
//href="http://www.larastudent.com:871/student/index?selects=1&page=1"
//此处就是模糊查询 1 后,下一页 处的链接,触发链接控制器处理数据,再返回就实现了。
网友评论