Download the PHP package jiaxincui/laravel-request-query without Composer

On this page you can find all versions of the php package jiaxincui/laravel-request-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-request-query

About

Eloquent request filter for laravel

使用示例

请求时使用对应的参数返回过滤后的数据

/api/users?where=age:gt:18

/api/users?where=name:like:foo;email:like:bar

/api/users?where=age:gt:18&slice=5,10&orderBy=id,desc

/api/users?where[]=age:gt:18&where[]=name:foo&slice=5,10&orderBy=id,desc

使用步骤

1. 在 Model 里使用 trait

use Jiaxincui\RequestFilter\FilterScope;

2. 创建 Filter

php artisan make:filter User

将生成一个 filter 类 App\Filters\UserFilter

你还需要显式定义可用于过滤的字段,见后续章节。

3. 在查询时添加 Filter

User::fitler(new UserFilter)->get()

4. 查询请求

/api/users?where=age:gt:18;name:foo

默认可用的方法

with

with 示例:with=userinfo

orderBy

orderBy (大小写敏感), 示例:orderBy=id,desc

slice

slice 示例: slice=5,10

trashed

trashed 示例: trashed=onlytrashed=with

where

wherewhere[] 示例:where=age:gt:18where[]=name:like:foo&where[]=age:gt:18

操作符

对于 where 一个查询参数分3段,并且使用: (冒号) 作为分隔符,分别代表字段、操作符、值

支持的操作符如下:

eq lt gt lte gte neq in notin between notbetween null notnull

注意

其中 null notnull 参数为2段

示例:where=card_number:null

列表项

列表项使用 , 作为分隔符

以下示例展示了分隔符 , 的使用

api/users?where=name:in:foo,bar&with=userinfo,adress&orderBy=id,desc&slice=5,10

自定义方法

除了使用默认方法,你还可以在生成的类里自定义方法

使用: /api/users?onlyVip=1

分组

对于 where 查询需要区分 andor , 以下示例可以告诉你答案

请留意 ; 符号的使用

示例1

/api/users?where=age:gt:18;name:foo

SQL age > 18 or neme = 'foo'

示例2

/api/users?where[]=age:gt:18&where[]=name:foo

SQL age > 18 and neme = 'foo'

示例3

/api/users?where[]=age:lte:18;vip:eq:1&where[]=name:foo

SQL (age > 18 or vip = 1) and neme = 'foo'

关联查询

基本

/api/users?with=userinfo 等同于 User::with('userinfo')->get();

带条件的关联查询

/api/users?with=userinfo&where=userinfo.age:gt:18 等同于 User::whereHas('userinfo', fn ($query) => $query->where('age', '>', 18)->get();

定义字段

安全起见,过滤器使用字段白名单机制,每个过滤器都需要显式定义可查询的列、可关联的表、可用于排序的列。 (如果没有定义,过滤器将不起任何作用)

你需要显式实现如下方法:

全局过滤

有时候你可能想要使用全局的过滤,你可以重写 applyBaseFilter 方法

这个方法应该返回 Builder 实例

License

MIT © JiaxinCui


All versions of laravel-request-query with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/console Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/filesystem Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jiaxincui/laravel-request-query contains the following files

Loading the files please wait ...