titasgailius/search-relations
Composer 安装命令:
composer require titasgailius/search-relations
包简介
A Laravel Nova tool.
关键字:
README 文档
README
This package allows you to include relationship columns into Laravel Nova search query.
Screenshot
Installation
composer require titasgailius/search-relations
Next, add Titasgailius\SearchRelations\SearchesRelations trait to your base resource class App\Nova\Resource
use Titasgailius\SearchRelations\SearchesRelations; abstract class Resource extends NovaResource { use SearchesRelations;
Usage
Simply add public static $searchRelations variable to any of your Nova resources.
This array accepts a relationship name as a key and an array of searchable columns as a value.
/** * The relationship columns that should be searched. * * @var array */ public static $searchRelations = [ 'user' => ['username', 'email'], ];
Alternatively, you may add a static searchableRelations() method to return an array of searchable relations.
/** * Get the searchable columns for the resource. * * @return array */ public static function searchableRelations(): array { return [ 'user' => ['username', 'email'], ]; }
Global search
You may customize the rules of your searchable relationships for global search by defining the $globalSearchRelations property.
/** * The relationship columns that should be searched globally. * * @var array */ public static $globalSearchRelations = [ 'user' => ['email'], ];
Alternatively, you may add a static globallySearchableRelations() method to return an array of globally searchable relations.
/** * Get the searchable columns for the resource. * * @return array */ public static function globallySearchableRelations(): array { return [ 'user' => ['email'], ]; }
Disabling global search for relationships
You may disable the global relationship search by declaring $globalSearchRelations with an empty array.
/** * The relationship columns that should be searched globally. * * @var array */ public static $globalSearchRelations = [];
Alternatevily, you may disable the global search for relationships by setting the $searchRelationsGlobally property to false.
/** * Determine if relations should be searched globally. * * @var array */ public static $searchRelationsGlobally = false;
Nested relationships
You may search nested relationships using dot notation.
/** * The relationship columns that should be searched. * * @var array */ public static $searchRelations = [ 'user.country' => ['code'], ];
Extending Search
You may apply custom search logic for the specified relations by retuning a class implementing a Search interface.
/** * Get the searchable columns for the resource. * * @return array */ public static function searchableRelations(): array { return [ 'country' => new LocationSearch(['USA', 'UK']), ]; }
Your custom search class must implement a simple Search interface that has a single method which accepts
the current query $query, a relationship name $relation and a search input $search.
<?php namespace Titasgailius\SearchRelations\Contracts; use Illuminate\Database\Eloquent\Builder; interface Search { /** * Apply search for the given relation. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $relation * @param string $search * @return \Illuminate\Database\Eloquent\Builder */ public function apply(Builder $query, string $relation, string $search): Builder; }
You may take a look at the Titasgailius\SearchRelations\Searches\RelationSearch class as an example.
titasgailius/search-relations 适用场景与选型建议
titasgailius/search-relations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.47M 次下载、GitHub Stars 达 357, 最近一次更新时间为 2018 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「nova」 「laravel」 「relations」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 titasgailius/search-relations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 titasgailius/search-relations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 titasgailius/search-relations 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
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.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 7.47M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 359
- 点击次数: 11
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-01
