您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Laravel4 restful controller分页

2024/3/5 13:33:20发布29次查看
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分页, 感谢原作者分享。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product