brunaobh/eloquent-ql
Composer 安装命令:
composer require brunaobh/eloquent-ql
包简介
A library that provides content negotiation
README 文档
README
This library helps to negotiate content related to eloquent models (fields, relations and filters)
Installation
Install the package using composer:
$ composer require brunaobh/eloquent-ql
Publish the package configuration: $ php artisan vendor:publish --provider="brunaobh\Search\Search\SearchServiceProvider"
That's it.
Simple usage
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; use Search; class UserController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $res = Search::handleRequest($request) ->negotiate('User') ->get(); return response()->json($res); }
Create your filter
public function scopeFilterByAddressNotNull($query) { return $query->whereNotNull('address'); }
Now you simply call your route with your filter and the fields you want to return in the request
http://localhost:8000/api/users?fields=name,email&filters=filterByAddressNotNull
Using with Laravel
Service Provider (Optional on Laravel 5.5)
Once Composer has installed or updated your packages you need add aliases or register you packages into Laravel. Open up config/app.php and find the aliases key and add:
Providers:
brunaobh\Search\Search\SearchServiceProvider::class,
Aliases:
brunaobh\Search\Search\SearchServiceProvider::class,
'Search' => brunaobh\Search\Facades\Search::class,
Contact
Bruno Coelho brunaobh@gmail.com
License
This project is distributed under the MIT License. Check [LICENSE][LICENSE.md] for more information.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-20