我正在尝试运行一个查询,该查询将带回已批准且 producttype(fk) id 为 5 的产品。目前它只返回所有已批准的产品并忽略产品类型。
我目前的代码。
$products =Product::where('approved', '=', 1, 'AND','producttype_id', '=', 5)->orderBy('productname');
关于如何做到这一点的任何想法?
您需要where()
像这样拆分和链接(或传递条件数组)方法:
<?php
// chaining
$products = Product::where('approved', 1)->where('producttype_id', 5)->orderBy('productname')->get();
// passing array of conditions
$products = Product::where([
[ 'approved', '=', 1 ],
[ 'producttype_id', '=', 5 ]
])->orderBy('productname')->get();
更多信息:查询生成器
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句