oscabrera/laravel-query-filters
最新稳定版本:v1.0.3
Composer 安装命令:
composer require oscabrera/laravel-query-filters
包简介
A Laravel package for advanced query filtering and conditions.
README 文档
README
A Laravel package for advanced query filtering and conditions.
Installation
Install the package via Composer:
composer require oscabrera/laravel-query-filters
Configuration (Optional)
You can publish the configuration file to customize the method name used for applying filters. This is optional, but it provides additional flexibility.
Publish the configuration file:
php artisan vendor:publish --provider="Oscabrera\QueryFilters\QueryFiltersServiceProvider" --tag="config"
This will create a config/query-filters.php file in your Laravel application. You can modify this file to change the
method name:
return [ /* * The name of the macro that is added to the Eloquent query builder. */ 'method_name' => 'applyFilters', ];
Usage
Here's an example of how to use the QueryFilters in a controller:
use Oscabrera\QueryFilters\Utilities\QueryFilters; use App\Models\User; use Illuminate\Http\Request; public function index(Request $request) { $conditions = [ 'name' => 'John', 'age' => ['age', '>', 25], 'status' => ['active', 'pending'], 'role' => [ 'subQuery' => function($query) { return $query->select('id') ->from('roles') ->where('name', 'admin'); }, 'not' => false, ] ]; $queryFilters = new QueryFilters($conditions); $users = User::query()->applyFilters($queryFilters)->get(); return response()->json($users); }
Features
- Simple Conditions: Apply simple equality conditions.
- Array Conditions: Use whereIn conditions for columns.
- Triple Conditions: Apply conditions with specific operators.
- SubQueries: Use subqueries for complex filtering.
- Customizable Method Name: Change the method name for applying filters via configuration.
More Information
For more information, visit the documentation.
By following these instructions, you can easily integrate advanced query filtering into your Laravel applications, customize the filtering method name, and keep your code clean and maintainable.
统计信息
- 总下载量: 632
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-06