tes/laravel-relafilter
Composer 安装命令:
composer require tes/laravel-relafilter
包简介
A lightweight Laravel package to filter model data through nested relationships using a simple input structure.
README 文档
README
Laravel Relafilter is a lightweight and expressive filtering package for Laravel models. It allows you to filter using deeply nested relationships without writing complex query logic.
⚠️ This package is not a replacement for Laravel's Query Builder. Instead, it's a lightweight and simpler alternative for specific use cases — especially useful in Livewire components or API filters.
🚀 Installation
composer require tes/laravel-relafilter
✅ Key Features
- Simple syntax using array-based filters
- Supports nested relationships (
employee.current_company.position.name) - Supports common query operators like
=,like,>,<,!= - Supports
whereBetweenfor date ranges - Perfect for use in Livewire or traditional controllers
🔧 Usage
🟢 In Livewire
<input type="text" class="form-control" placeholder="Position" wire:model.live.debounce.300="search.current_company_position.position.name:like">
use App\Models\Employee; class EmployeeList extends Component { public array $search = []; public function render() { $employees = Employee::filter($this->search)->get(); return view('livewire.employee-list', compact('employees')); } }
🟡 In Controller
use App\Models\Employee; use Illuminate\Http\Request; public function index(Request $request) { $employees = Employee::filter($request->input())->get(); return view('employees.index', compact('employees')); }
<input type="text" class="form-control" placeholder="Position" name="search[current_company_position][position][name:like]">
🔍 Supported Operators
| Syntax | SQL Equivalent | Example |
|---|---|---|
:like |
LIKE |
name:like => John |
:= |
= |
status:= => active |
:!= |
!= |
type:!= => admin |
:> |
> |
age:> => 30 |
:< |
< |
created_at:< => 2024-01-01 |
| default | LIKE |
If no operator provided |
🧠 How It Works
The filter() method inspects the keys of the input array, and for any nested key (e.g. company.manager.name:like), it automatically applies the correct whereHas or where clause.
It also supports additional logic such as range filtering using whereBetween, particularly for date ranges.
📅 Date Range Example
If both start and end values are present in the filters, it will apply a whereBetween clause on the start_date column:
if (isset($flatFilters['start']) && isset($flatFilters['end'])) { $query->whereBetween('start_date', [ $flatFilters['start'], Carbon::parse($flatFilters['end'])->endOfDay(), ]); }
✨ Example Filter Input (Array)
[
'company.name:like' => 'Tesla',
'current_company_position.position.name:like' => 'Developer',
'status' => 'active',
'created_at:>' => '2024-01-01',
'start' => '2024-06-01',
'end' => '2024-06-30',
]
🧩 Integration
Make sure your model uses the HasRelafilter trait:
use Tes\LaravelRelafilter\Traits\HasRelafilter; class Employee extends Model { use HasRelafilter; }
📦 Package Status
This package is still in early development. Please report any issues or suggestions via GitHub.
📄 License
This package is open-source software licensed under the MIT license.
tes/laravel-relafilter 适用场景与选型建议
tes/laravel-relafilter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tes/laravel-relafilter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tes/laravel-relafilter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-23