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

Laravel4 restful controller分页

WBOY
WBOY原创
2016-06-06 20:09:531539浏览

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