我正在尝试查询 Eloquent 中的关系。
$deliveryOverride = $product->days->whereNotNull('margin')
->where('price_id', $order['price_id'])
->where('product_id', $product->id)
->where('sale_at', date('Y-m-d', strtotime($day)))
->first();
我不断收到错误
方法 whereNotNull 不存在。
有任何想法吗?
当您直接在 Eloquent 对象上调用关系属性时,将执行查询并返回一个集合。WhereNotNull
集合没有功能。
如果要使用该函数查询关系,则必须直接调用关系函数。这对于性能也会更好,因为查询将发生在数据库上。
$deliveryOverride = $product->days() // Call relation function here
->whereNotNull('margin')
->where('price_id', $order['price_id'])
->where('product_id', $product->id)
->where('sale_at', date('Y-m-d', strtotime($day)))
->first();
可以在此处的文档中找到有关此的更多信息:https : //laravel.com/docs/5.7/eloquent-relationships#querying-relations
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句