我收到此错误:
类Illuminate \ Database \ Eloquent \ Builder的对象无法转换为字符串
当我运行此代码时:
public function index()
{
save_resource_url();
//$items = News::with(['category', 'photos'])->get();
$items = Solicitud::rightjoin(News::with(['category', 'photos']),'news.id','=','solicitud.event_id')->count('*','event_id','as','total')->get();
return $this->view('news_events.index', compact('items'));
}
我原来的sql查询
SELECT *,count(event_id)as total FROM solicitud RIGHT JOIN news ON news.id = solicitud.event_id group by title;
2 回答
解决:
我的原始代码
改变我的SQL查询:
此查询生成了重复的列
为了这:
此查询仅显示users表的列以及与'request'表相关的'total'表
在我的代码转换为雄辩
您得到的错误是因为您将
Builder
作为第一个参数News::with(['category', 'photos'])
. 它应该只是字符串(表名),如'news'
.Click here to read more
所以查询应该