我只是编写一个查询来获取所有帖子数据,它与其他表格相关。当我尝试加载内部查询时,它返回错误
解析错误:语法错误,意外'功能'(T_FUNCTION),期待']'
我的型号代码:
Post::with('product.categories.attributes' => function() {
$query->whereHas('post_attribute', function ($query) {
$query->where('attribute_id', '=', 'attributes.id' );
});
})->whereStatus("Active")->get();
我的查询中有什么问题。
答案 0 :(得分:1)
Constraining Eager Loads时语法错误。您应该将relationship
作为键和闭包传递给数组
Post::with(['product.categories.attributes' => function($query) {
$query->whereHas('post_attribute', function ($query) {
$query->where('attribute_id', '=', 'attributes.id');
});
}])->whereStatus("Active")->get();