首頁 >php教程 >php手册 >Laravel4 restful controller分页

Laravel4 restful controller分页

WBOY
WBOY原創
2016-06-06 20:09:531549瀏覽

Laravel4 restful controller分页,使用下面方法分页报错:The Response content must be a string or object implementing __toString(), object given. class ApiController extends BaseController { protected $restful =true; public function getIndex(

Laravel4 restful controller分页,使用下面方法分页报错:The Response content must be a string or object implementing __toString(), “object” given.

class ApiController extends BaseController
{
protected $restful =true;
public function getIndex()
{
//博客首页
$p = Input::get(‘p’,1);
$blogs = Blog::with(‘author’)->orderBy(‘created_at’, ‘desc’)->paginate(20);
return $blogs;
}

}

今天被Laravel4 restful controller分页问题困扰了一天,今晚终于忍不住翻看源码,终于找到了解决方法:

class ApiController extends BaseController
{
protected $restful =true;
public function getIndex()
{
//博客首页
$p = Input::get(‘p’,1);
$blogs = Blog::with(‘author’)->orderBy(‘created_at’, ‘desc’)->select(‘id’, ‘title’)->forPage($p,2)->get();//paginate(20);
return $blogs;
}

}

现在分享出来希望对大家有帮助

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn