Laravel4 restful controller分页
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;
}
}
现在分享出来希望对大家有帮助
原文地址:Laravel4 restful controller分页, 感谢原作者分享。