Laravel:查询生成器中的意外函数(T_函数)
我只是编写一个查询来获取所有post数据,并将其与其他表关联。当我尝试加载内部查询时,它返回错误 分析错误:语法错误,意外的“函数”(T_函数),应为“]” 我的型号代码:Laravel:查询生成器中的意外函数(T_函数),laravel,laravel-5.5,Laravel,Laravel 5.5,我只是编写一个查询来获取所有post数据,并将其与其他表关联。当我尝试加载内部查询时,它返回错误 分析错误:语法错误,意外的“函数”(T_函数),应为“]” 我的型号代码: Post::with('product.categories.attributes' => function() { $query->whereHas('post_attribute', function ($query) {
Post::with('product.categories.attributes' => function() {
$query->whereHas('post_attribute', function ($query) {
$query->where('attribute_id', '=', 'attributes.id' );
});
})->whereStatus("Active")->get();
我的查询中有什么问题。您在查询时出现语法错误。您应该将
关系
作为键传递,将闭包作为数组中的值传递
Post::with(['product.categories.attributes' => function($query) {
$query->whereHas('post_attribute', function ($query) {
$query->where('attribute_id', '=', 'attributes.id');
});
}])->whereStatus("Active")->get();
'product.categories.attributes'=>函数(){..
@linktoahef update code获得相同的错误,请检查查询产品.类别.属性
关系中的此表..现在有另一个表post\u attributes
我想将attribute\u id
与post\u attributes
表进行比较。@Javed抱歉,我对该查询没有任何线索。也许你可以问一下新问题或使用相关详细信息更新当前问题https://stackoverflow.com/questions/50215037/laravel-join-within-query-using-eloquent
帮我看看这个。。