php - Laravel 在 eloquent 查询期间使用计算
问题描述
我想查询所有净价低于一定金额的产品。在我的表中,我只存储总价和折扣,其中净价是总价和折扣之间的差额
在我的表中,我有以下列
产品表
name,
gross_price,
discount_amount
所以在我的查询中,我想获取所有gross_price - discount_amount
小于一定数量的项目,如 100
所以目前正在使用雄辩的喜欢
Product::where('', '<', 100) //stuck on how to add new net_price in the query
我坚持如何将计算添加到我的查询中。如何在不需要向表中添加另一个字段的情况下添加计算?
解决方案
尝试使用---
Product::where(\DB::raw('(gross_price - discount_amount)'),'<',100);
希望它会帮助你。
推荐阅读
- discord.py - 我将如何使命令切换命令服务器特定
- python - 将泛型类型传递给内部类
- hyperledger-fabric - 使用 Fabric 测试网络时出现 ClientHandshake 错误
- .net-core - Microsoft 标识用户 ID 数据类型
- kotlin - 你如何找到 Kotlin coroutineContext 的元素?
- java - 将存储的整数发送到方法?
- python - 根据相邻的差值将列表分组
- asp.net-identity - 社交登录的 AspNetBoilerplate 身份验证声明
- refresh - 任务状态更改时自动更新 Appian 网页?
- hdfs - HDFS 平衡器 - 适用于具有 1KB 文件的集群