Example of Laravel Framework Search Paging Feature
- 2021-11-14 05:08:31
- OfStack
This article illustrates the search paging function of Laravel framework. Share it for your reference, as follows:
Controller controller
/**
* Article search
*
* @author YING
* @param void
* @return void
*/
public function mesArticleSearch()
{
// Connection value
$input=Input::get();
// Call model query
// Instantiate class
$cate=new Article();
// Call a custom method Query classification
$artInfo=$cate->searchAll($input);
// From session User name of
$username=session('user_name');
// Instantiate class
$cate=new Category();
// Call a custom method Query classification
$cateInfo=$cate->selectAll();
return view('admin.article',['username'=>$username,'artInfo'=>$artInfo,'cateInfo'=>$cateInfo,'cate_id'=>$input['cate_id'],'title'=>$input['title']]);
}
Model model
/**
* Article search
*
* @author YING
* @param void
* @return void
*/
public function searchAll($input)
{
// Judge
if($input['cate_id']!=0&&$input['title']!=""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where(array('category.cate_id'=>$input['cate_id']))
->where('title','like','%'.$input['title'].'%')
->orderBy('article.sort','DESC')
->paginate(3);
}else if($input['cate_id']!=0&&$input['title']==""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where(array('category.cate_id'=>$input['cate_id']))
->orderBy('article.sort','DESC')
->paginate(3);
}else if ($input['cate_id']==0&&$input['title']!=""){
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->where('title','like','%'.$input['title'].'%')
->orderBy('article.sort','DESC')
->paginate(3);
}else{
return $this->join('user','u_id','=','user.Id')
->join('category','article.cate_id','=','category.cate_id')
->select('user_name','cate_name','article.*')
->where('category.status','0')
->orderBy('article.sort','DESC')
->paginate(3);
}
}
Compare low
View view
<div class="list-page" style="margin-left: 400px">
{{$artInfo->appends(['cate_id' => $cate_id])->appends(['title' => $title])->render()}}
</div>
More readers interested in Laravel can check the topics of this site: "Introduction and Advanced Tutorial of Laravel Framework", "Summary of Excellent Development Framework of php", "Introduction Tutorial of php Object-Oriented Programming", "Introduction Tutorial of php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
I hope this article is helpful to PHP programming based on Laravel framework.