【发布时间】:2021-02-20 19:26:42
【问题描述】:
我有两个模型,分别命名为“Products”和“Product_options”,每个产品都有很多选项。
我想选择那些至少有一个选项为真的产品。
我已经走了这么远,
class Product extends Model
{
use HasFactory;
public function options()
{
return $this->hasMany(Product_options::class, 'product_id', 'id');
}
}
$products = Product::whereDoesntHave('options', function ($query) {
$query->where('available','not', ' 1');
})
->has('options', '>', 0)
->get();
dd($products);
但如果一个产品有一个或多个选项,其中 avaible 为真,而一个或多个选项为假,则不会选择产品。
附言对不起我的英语。
【问题讨论】:
-
欢迎来到SO ...你的英语很好,可能比一些母语人士更好:)
标签: php laravel eloquent laravel-8