Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zyimm/laravel-query-builder
是laravel框架根据已有配置来执行查询条件构造器服务包,再也不把查询写成意大利面条的代码了|Query condition builder service package of laravel framework
https://github.com/zyimm/laravel-query-builder
laravel laravel-query-builder sql
Last synced: about 1 month ago
JSON representation
是laravel框架根据已有配置来执行查询条件构造器服务包,再也不把查询写成意大利面条的代码了|Query condition builder service package of laravel framework
- Host: GitHub
- URL: https://github.com/zyimm/laravel-query-builder
- Owner: zyimm
- License: apache-2.0
- Created: 2020-07-30T08:04:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-06T02:37:21.000Z (about 1 year ago)
- Last Synced: 2024-04-09T14:34:20.771Z (8 months ago)
- Topics: laravel, laravel-query-builder, sql
- Language: PHP
- Homepage:
- Size: 50.8 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## laravel-query-builder
> laravel-query-builder 是laravel框架根据已有配置来执行查询条件构造器服务包,再也不把查询写成意大利面条的代码了。|laravel-query-builder is a service pack of the laravel framework for executing conditional query builders based on existing configurations.
## Install&安装
```
composer require zyimm/laravelquery-builder
```## Require&依赖
```json
{
"require": {
"php": ">=7.0",
"fideloper/proxy": "^4.0",
"laravel/framework": ">=5.5"
}
}
```
## Usage & 用例
```php
/**
*目前支持条件操作符
'=',
'<>',
'>',
'>=',
'<',
'<=',
'like',
'full_like',
'in',
'not_in',
'between',
'not_between'
**/
use Illuminate\Support\Facades\DB;
use zyimm\query\build\QueryWhere;
/**
* @var QueryWhere $build
*/
$build = app('QueryWhere');//提交过来数据
$data = [
'log_id' => 20,
'user_id'=> 'zyimm',
'user_name' => "zyimm,12"
];//配置数据库字段查询操作
$condition =[
'=' => [
'log_id'
],
'not_in' => [
'user_id'
],
'between' => [
'user_name'
],
'full_like' => [
'user_id'
],
'<>' => [
'user_id'
],
'>' => [
'user_id'
]
];
DB::enableQueryLog();
//model
\App\Models\Log::query()
->where(function ($query) use ($build, $data, $condition){
$build->buildQueryWhere($data ,$condition, $query);
})->get();
dd(DB::getQueryLog());
```
生成SQL查询记录如下截图:
![生成SQL查询记录](http://api.img.zyimm.com/media/20201012/bae11974ff1496f95b2eb9a8dabb7d22.jpg)**提示**:
'in','not_in','between','not_between'标识符支持数组和字符串,字符串可选 ','和'.'作为分隔符。## issue
能力有限!欢迎提出issue,共同学习进步。