开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 2 Fork 2

MADONG/Query

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
标签 (1)
main
v1.0.1
main
分支 (1)
标签 (1)
main
v1.0.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
标签 (1)
main
v1.0.1
query
/
src
/
QueryCondition.php
query
/
src
/
QueryCondition.php
QueryCondition.php 4.27 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.April 提交于 2026年03月11日 11:46 +08:00 . initial commit
<?php
/**
*+------------------
* madong
*+------------------
* Copyright (c) https://gitee.com/motion-code All rights reserved.
*+------------------
* Author: Mr. April (405784684@qq.com)
*+------------------
* Official Website: http://www.madong.tech
*/
namespace madong\query;
use Illuminate\Database\Eloquent\Builder;
/**
* 查询条件对象
* 封装单个查询条件,支持多种操作符
*/
class QueryCondition
{
/**
* @param string $field 字段名
* @param string $operator 操作符
* @param mixed $value 值
*/
public function __construct(
public readonly string $field,
public readonly string $operator,
public readonly mixed $value
) {}
/**
* 应用到查询构建器
*
* @param Builder $query
* @return Builder
*/
public function apply(Builder $query): Builder
{
return match ($this->operator) {
'eq' => $query->where($this->field, '=', $this->value),
'ne' => $query->where($this->field, '!=', $this->value),
'gt' => $query->where($this->field, '>', $this->value),
'gte' => $query->where($this->field, '>=', $this->value),
'lt' => $query->where($this->field, '<', $this->value),
'lte' => $query->where($this->field, '<=', $this->value),
'like' => $query->where($this->field, 'like', "%{$this->value}%"),
'ilike' => $query->where($this->field, 'ilike', "%{$this->value}%"),
'in' => $query->whereIn($this->field, is_array($this->value) ? $this->value : explode(',', $this->value)),
'not_in' => $query->whereNotIn($this->field, is_array($this->value) ? $this->value : explode(',', $this->value)),
'between' => $query->whereBetween($this->field, is_array($this->value) ? $this->value : explode(',', $this->value)),
'not_between' => $query->whereNotBetween($this->field, is_array($this->value) ? $this->value : explode(',', $this->value)),
'null' => $query->whereNull($this->field),
'not_null' => $query->whereNotNull($this->field),
default => $query,
};
}
/**
* 静态工厂方法:等于
*/
public static function eq(string $field, mixed $value): self
{
return new self($field, 'eq', $value);
}
/**
* 静态工厂方法:不等于
*/
public static function ne(string $field, mixed $value): self
{
return new self($field, 'ne', $value);
}
/**
* 静态工厂方法:大于
*/
public static function gt(string $field, mixed $value): self
{
return new self($field, 'gt', $value);
}
/**
* 静态工厂方法:大于等于
*/
public static function gte(string $field, mixed $value): self
{
return new self($field, 'gte', $value);
}
/**
* 静态工厂方法:小于
*/
public static function lt(string $field, mixed $value): self
{
return new self($field, 'lt', $value);
}
/**
* 静态工厂方法:小于等于
*/
public static function lte(string $field, mixed $value): self
{
return new self($field, 'lte', $value);
}
/**
* 静态工厂方法:模糊匹配
*/
public static function like(string $field, mixed $value): self
{
return new self($field, 'like', $value);
}
/**
* 静态工厂方法:包含
*/
public static function in(string $field, mixed $value): self
{
return new self($field, 'in', $value);
}
/**
* 静态工厂方法:范围
*/
public static function between(string $field, mixed $value): self
{
return new self($field, 'between', $value);
}
/**
* 静态工厂方法:为空
*/
public static function null(string $field): self
{
return new self($field, 'null', null);
}
/**
* 静态工厂方法:不为空
*/
public static function notNull(string $field): self
{
return new self($field, 'not_null', null);
}
/**
* 转换为数组
*/
public function toArray(): array
{
return [
'field' => $this->field,
'operator' => $this->operator,
'value' => $this->value,
];
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

一个强大的查询参数解析和过滤库,为 PHP 8.1+ 项目提供灵活、类型安全的查询构建能力。
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/motion-code/query.git
git@gitee.com:motion-code/query.git
motion-code
query
Query
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /