nickfla1 / search-relations
Laravel Nova 工具。
此软件包的规范存储库似乎已消失,因此软件包已被冻结。
1.1.2
2020-02-10 10:16 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2020-11-10 12:23:31 UTC
README
此软件包允许您将关系列包含到 Laravel Nova 搜索查询中。
截图
安装
composer require titasgailius/search-relations
接下来,将 Titasgailius\SearchRelations\SearchesRelations
特性添加到您的基资源类 App\Nova\Resource
use Titasgailius\SearchRelations\SearchesRelations; abstract class Resource extends NovaResource { use SearchesRelations;
用法
简单地将 public static $searchRelations
数组添加到任何您的 Nova 资源中。此数组以关系名称作为键,以搜索列的数组作为值。
/** * The relationship columns that should be searched. * * @var array */ public static $searchRelations = [ 'user' => ['username', 'email'], ];
全局搜索
您可以通过在 nova 资源中定义 $searchRelationsGlobally
属性来禁用关系列的全局搜索。
/** * Determine if relations should be searched globally. * * @var array */ public static $searchRelationsGlobally = false;
当您已禁用关系的全局搜索时,您仍可以像这样为特定的关系启用它
/** * Determine if relations should be searched globally. * * @var array */ public static $searchRelationsGlobally = false; /** * The relationship columns that should be searched globally. * * @var array */ public static $globalSearchRelations = [ 'user' => ['email'], ];
现在,在全局搜索时,Laravel Nova 将 忽略 在 $searchRelations
中声明的关联,而将使用 $globalSearchRelations
。
嵌套关系
您可以使用点符号来搜索嵌套关系。
/** * The relationship columns that should be searched. * * @var array */ public static $searchRelations = [ 'user.country' => ['code'], ];