skyraptor/modelsearch
Composer 安装命令:
composer require skyraptor/modelsearch
包简介
关键字:
README 文档
README
Laravel ModelSearch is a lightweight, easy to use package to create dynamic search queries for specific Models with Laravel or Illuminate 5.8.
Requirements
- Laravel 5.7+
Installation
Composer
Simply run composer require skyraptor/modelsearch to install the package in its latest version, after that run composer update. The package will register its own ServiceProvider using Laravels package discovery.
Configuration
This package includes its own configuration file which you should publish by with the command php artisan vendor:publish and following the instuctions on screenafterwards. In the configuration file you have to adjust the namespace for you filters directory and your request filter prefix.
return [ 'filtersFQCN' => 'App\\Filters\\', 'requestFilterPrefix' => 'filter_' ];
Filters
In order to define a filter you have to create a folder that is named as your model within your filters directory. Within this folder you can create filter specific to the model.
For example:
path\to\laravel\app\Filters\User\HasId.php
Your filter has to extend ModelSearch\Contracts\Filter.
<?php namespace App\Filters\User; use ModelSearch\Contracts\Filter; use Illuminate\Database\Eloquent\Builder; class HasId implements Filter { /** * Apply a given search value to the builder instance. * * @param Builder $builder * @param integer $value * @return Builder $builder */ public static function apply(Builder $builder, $value) { return $builder->where( 'id', $value ); } }
Request Filters
The request filter prefix in the configuration defines the prefix being used for filter names in the request parameters. This can be used to allow the user to apply filters trought POST and GET requests. This has to be done manually by calling the addRequestFilters method and providing a Request instance.
Always remember to apply filters in the appropiate order.
$search = new ModelSearch( User::class ); $search->addRequestFilters( $request ); $result = $search->result();
You can change the filter prefix of the Search after by calling the setRequestFilterPrefix() method, providing a new preifx.
Examples
The following example shows you how to use the Search in your Controller:
namespace ModelSearch\ModelSearch; public function someController( Request $request ) { ... $search = new ModelSearch( User::class ); $search->addFilters([ 'HasId' => 1, 'HasLastName' => 'Doe' ]); $search->addFilter('SomeFilter', 'value'); $result = $search->result(); // The search can be extended after processing results $search->addFilter('AnotherFilter', 'value'); $result2 = $search->result(); ... }
skyraptor/modelsearch 适用场景与选型建议
skyraptor/modelsearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「query」 「modelsearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 skyraptor/modelsearch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 skyraptor/modelsearch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 skyraptor/modelsearch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Query filtering in your frontend
Abstraction Layer to index and search entities
Anax Database Active Record module for model classes.
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-29