定制 plin-code/laravel-full-name 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

plin-code/laravel-full-name

Composer 安装命令:

composer require plin-code/laravel-full-name

包简介

Search and sort Eloquent queries and Filament tables by a person's full name across first_name and last_name columns, with BelongsTo and HasOne relation support and multi-token matching.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status PHPStan Action Status Total Downloads

Search and sort Eloquent queries (and Filament tables) by a person's full name stored across two columns (first_name and last_name), either on the main model or on a BelongsTo / HasOne relation.

What it solves

Filament's built-in ->searchable(['first_name', 'last_name']) searches each column independently, which fails for composite queries like "mario rossi". The native ->sortable(query: ...) works for direct columns but requires repetitive custom join logic for relation-based sort. This package encapsulates the solution once, tested once, documented once.

Installation

composer require plin-code/laravel-full-name

No config file, no migrations, no Blade views, no Artisan command. The service provider auto-registers.

Requirements

  • PHP 8.4
  • Laravel 12 or 13
  • Filament 4 or 5 (optional, only needed for the Filament layer)
  • MySQL 8, PostgreSQL 14+, or SQLite 3

Quick start

Standalone Eloquent

Booking::query()
    ->searchFullName($request->input('q'))
    ->orderByFullName('asc')
    ->paginate();

Booking::query()
    ->searchFullName($request->input('q'), relation: 'user')
    ->orderByFullName('asc', relation: 'user')
    ->paginate();

Filament, direct columns

use Filament\Tables\Columns\TextColumn;

TextColumn::make('full_name')
    ->fullNameSearchable()
    ->fullNameSortable();

Filament, via BelongsTo

TextColumn::make('user.full_name')
    ->fullNameSearchable(relation: 'user')
    ->fullNameSortable(relation: 'user');

Filament, via HasOne

// User hasOne(Hiker::class) — search and sort users by their hiker full name.
TextColumn::make('hiker.full_name')
    ->fullNameSearchable(relation: 'hiker')
    ->fullNameSortable(relation: 'hiker');

Custom column names

TextColumn::make('full_name')
    ->fullNameSearchable(
        firstNameColumn: 'given_name',
        lastNameColumn: 'family_name',
    )
    ->fullNameSortable(
        firstNameColumn: 'given_name',
        lastNameColumn: 'family_name',
    );

The complete API surface lives in docs/api.md.

Performance considerations

The matching strategy uses LOWER(CONCAT(COALESCE(first, ''), ' ', COALESCE(last, ''))) which prevents btree indexes from being used on first_name or last_name. On tables up to a few hundred thousand rows this is typically acceptable for admin panel search. For very large tables, pair this package with a dedicated search engine (Meilisearch, Scout, Algolia) and use this package only for sort.

Matching behavior

The core uses LOWER(CONCAT(COALESCE(first, ''), ' ', COALESCE(last, ''))) matched with LIKE ? ESCAPE '!' in both forward and reversed concatenation forms.

Query Record Matches
mario first_name='Mario', last_name='Rossi' yes
rossi first_name='Mario', last_name='Rossi' yes
mario rossi first_name='Mario', last_name='Rossi' yes
rossi mario first_name='Mario', last_name='Rossi' yes
maria first_name='Marianna', last_name='Rossi' yes (substring, single token)
maria rossi first_name='Marianna', last_name='Rossi' no (multi token)
marianna rossi first_name='Marianna', last_name='Rossi' yes
mario giovanni rossi first_name='Mario Giovanni', last_name='Rossi' yes
rossi mario giovanni first_name='Mario Giovanni', last_name='Rossi' yes
bianchi mario first_name='Mario', last_name='Rossi Bianchi' yes

The asymmetry between single token and multi token queries is intentional and emerges from the SQL pattern. Single token queries use substring match, so maria matches records containing maria anywhere in either column. Multi token queries require the tokens to appear contiguously with the separating space between them in the concatenated first last or last first form, so maria rossi matches Maria Rossi but not Marianna Rossi (the separator space is not present between maria and rossi in the concatenation). Single token queries are exploratory (the user may be typing a prefix), multi token queries target a specific person.

See docs/conventions.md for the rationale behind the naming split between the Eloquent and Filament layers.

Limitations

  1. Only the BelongsTo and HasOne relation types are supported. HasMany, BelongsToMany, MorphTo, and nested relations raise UnsupportedRelationException at query build time.
  2. Accent and diacritic normalization is delegated to the database collation. On MySQL, use utf8mb4_unicode_ci or utf8mb4_0900_ai_ci. On PostgreSQL, consider the unaccent extension if needed.
  3. Fuzzy matching (soundex, metaphone, Levenshtein, trigram) is out of scope.
  4. Single column full name (one name column) is not handled. Filament's native ->searchable(['name']) covers that case already.
  5. Empty or whitespace only search input leaves the query unchanged (no WHERE clause is added).
  6. When combining orderByFullName(relation: ...) with an explicit ->select([...]) on the main query, qualify the column names with the main table name (for example ->select(['test_bookings.id']) rather than ->select(['id'])). The package performs a joinSub under the hood, which can introduce ambiguity for unqualified columns that exist on both tables.

Testing

composer test
composer analyse
composer format

Contributing

Please see CONTRIBUTING for details.

Changelog

Please see CHANGELOG for recent changes.

Credits

License

The MIT License (MIT). Please see License File for more information.

plin-code/laravel-full-name 适用场景与选型建议

plin-code/laravel-full-name 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 111 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「search」 「sort」 「laravel」 「eloquent」 「filament」 「filament-tables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 plin-code/laravel-full-name 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-21