Download the PHP package matrix-lab/laravel-advanced-search without Composer

On this page you can find all versions of the php package matrix-lab/laravel-advanced-search. 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-advanced-search

Laravel Advanced Search (Laravel 高级搜索)

几乎任何一个系统,都会涉及到搜索,并且可以搜索的项也很可能多。特别是做一些 OA 、ERP 、 CMS 、CRM 等后台系统的时候,各种报表,各种维度的搜索,非常常见。

一个系统会有非常多的列表。每个列表,可能要搜索的字段会有十来个或者更多。搜索的种类有 like 、全等、包含、区间、具体的业务条件等等。

没有经验的程序员可能会在 controller 里面写非常多的判断,非常多的 query 查询。就算是一些有经验的程序员,也很头疼该如何设置写这些逻辑,如何写的优雅。

我做了很多的后台系统,深知其中的痛楚,所以有了这个包,来一刀命中要害,让复杂的搜索简单起来,便于维护,容易理解,同时也变得优雅起来。

示例和对比

过去你可能这么写

现在你可能这么写

安装

composer require "matrix-lab/laravel-advanced-search"

使用

丰富的传参内容

fireInput

如果传递的参数内容并不能满足需要,还需要进行一些简单的加工,可以这样做:

这样就能通过 ?name=张 来获取所有姓张的员工。

fireInput 方法 第一个参数:前端的传参 key 第二个参数:处理这个传参的内容

fireInput 行为 如果不能够获取前端传参,那么直接返回 null ,也就是后续处理中会过滤都这条 where 规则 如果能够获取值,那么将获取值传递到闭包,可以自由的进行处理

appendInput

如果仅仅是想在获取的参数值后面添加数据,可以这样来:

但是你可能会问,为什么不获取数据之后直接添加 %

第二种写法是错误的,因为可能返回结果是这样的,当前端没有传参时,结果如下:

这样会按照值为 % 进行搜索。

when

当这个人是被禁用户的时候,我们会额外添加一个搜索条件,不让该用户搜索到任何内容

这里会根据 user()->locked_at 值进行判断,得到的结果如下

根据之前约定的,如果 键值 为空值(包括空字符串,但不包括 0 ),这个条件就不会生效

when 还有以下用法,满足你的各种需求:

RAW

原生的 DB::raw 我们也要支持,这个不需要别的,只需要你的语句,只要你会 sql,就可以写

闭包

如果你的查询特别复杂,以上各种形式都满足不了,那么你可以祭出终极大招了

闭包只有一个传参,$qIlluminate\Database\Eloquent\Builder。看到了这个类,你应该知道如何去使用了吧!

这个就是原生的 laravel 查询对象,把所有你需要的查询放里面吧!剩下不多说,自由发挥去吧!

and or

查询的时候,经常会有一些逻辑,他们之间可能是 and 或者是 or

默认 created_at大于小于 操作是 and 关联,

如果需要 or 操作,可以这样写

自定义的 laravel 本地作用域

上面的代码会在执行的时候,会调用模型的 scopeListByUser 方法。

如果需要传参:

上面的代码等同于

When 对象操作

执行的结果为

贡献

有什么新的想法和建议,欢迎提交 issue 或者 Pull Requests

协议

MIT


All versions of laravel-advanced-search with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
illuminate/support Version 5.8|6.*|7.*|8.*
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 matrix-lab/laravel-advanced-search contains the following files

Loading the files please wait ....