divineomega/laravel-natural-where

Laravel Natural Where 扩展了 Laravel 查询构建器,允许使用自然语言表达 where 操作符。

v2.1.0 2020-09-10 09:25 UTC

This package is auto-updated.

Last update: 2024-09-10 18:10:21 UTC


README

Laravel Natural Where 扩展了 Laravel 查询构建器,允许使用自然语言表达 where 操作符。

安装

要从项目的根目录安装 Laravel Natural Where,请运行以下命令。

composer require divineomega/laravel-natural-where

使用

请参阅以下基本使用示例。

$query = \App\User::query()
    ->naturalWhere('created_at', 'is between the years', ['2018', '2020'])
    ->naturalWhere('email', 'contains the word', 'jordan')
    ->naturalWhere('name', 'is not', 'Jordan Smith')
    ->naturalWhere('id', 'is one of the following', [1, 2, 3])
    ->get();

此示例将生成以下 SQL 查询。

select * from `users` where (`created_at` >= '2018' and `created_at` <= '2020') 
and `email` LIKE '%jordan%' and `name` != 'Jordan Smith' and `id` in (1, 2, 3)