承接 webard/nova-eloquent-searchable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webard/nova-eloquent-searchable

Composer 安装命令:

composer require webard/nova-eloquent-searchable

包简介

README 文档

README

This simple package comes with two solutions:

  1. Make ability to search Eloquent models by Laravel Nova way, using their search configuration
  2. Introduce additional search classes with optional value validating

Installation

composer require webard/nova-eloquent-searchable

Search Eloquent models like Nova resources

  1. Move public static $search or public static searchableColumns() definition from Nova Resource to Model.
  2. Add trait to your Nova Resource
use Webard\NovaEloquentSearchable\Trait\NovaEloquentSearch;

class User extends Resource
{
    use NovaEloquentSearch;
}
  1. Add trait to your model:
use Webard\NovaEloquentSearchable\Trait\EloquentSearchable;

class User extends Authenticatable
{
    use EloquentSearchable;
}

Now, you can search your models and return values the same way like in Laravel Nova panel:

$user = User::searchInDatabase('test@example.com')->first();

dump($user->name);

To not conflict with Laravel Scout, scope was called searchInDatabase, but if you want use other name, e.g. search, just rename Trait method:

class User extends Authenticatable
{
    use EloquentSearchable {
        scopeSearchInDatabase as scopeSearch;
    }
}

Now, you can search by search method:

$user = User::search('test@example.com')->first();

dump($user->name);

Additional search classes

Laravel Nova comes with some Searchable Columns Classes, but they can search only via MySQL's LIKE or full-text search.

Full-text search is powerful, but "like" searches on large datasets are very inefficient and they cannot use indexes, so this package derives several additional classes along with value validation functionality to optimize searches.

EqualValue

use Webard\NovaEloquentSearchable\Query\Search\EqualValue;


public static function searchableColumns(): array
{
    return [
        'name',
        (new EqualValue('email'))
    ];
}

EqualValue is used to search for full values. This is a simple comparison in MySQL WHERE column="value". This search method is useful, for example, for searching by e-mail address or telephone number.

Additionally, you can add value validation, so that if the passed value does not meet the condition, it will not be added to the search query.

use Webard\NovaEloquentSearchable\Query\Search\EqualValue;

public static function searchableColumns(): array
    {
        return [
            'name',
            (new EqualValue('email'))
                ->validate(fn($value) => Validator::make(
                    [
                        'value' => $value
                    ],
                    [
                        'value' => 'email'
                    ]
                )
                ->passes()
            ),
        ];
    }

EqualRelation

EqualRelation class do the same thing as EqualValue, but basing on relation instead of column.

Example:

use Webard\NovaEloquentSearchable\Query\Search\EqualValue;

public static function searchableColumns(): array
    {
        return [
            'name',
            (new EqualRelation('additionalEmails', 'email'))
                ->validate(fn($value) => Validator::make(
                    [
                        'value' => $value
                    ],
                    [
                        'value' => 'email'
                    ]
                )
                ->passes()
            ),
        ];
    }

FullTextValue

FullTextValue do the same thing as SearchableText class from Laravel Nova, but additionally adds double quote (") characters to search value. So if you search for John Doe, to SQL query there is sent "John Doe" value. This way, searching in full-text mode is more precise.

Of course value validation like in EqualValue is present too.

FullTextRelation

As above, but works with relations instead of columns.

Of course value validation like in EqualValue is present too.

TODO

I'm are actively seeking contributions to enhance this package. Here are some features I would love to see implemented:

  • tests
  • add validate method to Laravel Nova searchable classes
  • more searchable classes?

Contributing

We welcome contributions to improve this plugin! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive messages.
  4. Push your changes to your forked repository.
  5. Open a pull request to the main repository.

License

This project is licensed under the MIT License. See the LICENSE.md file for more details.

Contact

For questions or support, please open an issue on GitHub.

webard/nova-eloquent-searchable 适用场景与选型建议

webard/nova-eloquent-searchable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.77k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webard/nova-eloquent-searchable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webard/nova-eloquent-searchable 我们能提供哪些服务?
定制开发 / 二次开发

基于 webard/nova-eloquent-searchable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-23