brunaobh / eloquent-ql
一个提供内容协商的库
1.0.4
2018-06-20 15:18 UTC
Requires
- illuminate/http: ^5.6
Requires (Dev)
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2024-09-20 21:17:11 UTC
README
此库帮助协商与eloquent模型(字段、关系和过滤器)相关的内容
安装
使用composer安装包
$ composer require brunaobh/eloquent-ql
发布包配置:$ php artisan vendor:publish --provider="brunaobh\Search\Search\SearchServiceProvider"
就这样。
简单用法
<?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); }
创建您的过滤器
public function scopeFilterByAddressNotNull($query) { return $query->whereNotNull('address'); }
现在您只需调用带有您的过滤器和请求中要返回的字段的路由
https://:8000/api/users?fields=name,email&filters=filterByAddressNotNull
与Laravel一起使用
服务提供者(Laravel 5.5可选)
一旦Composer安装或更新了您的包,您需要将别名或注册您的包添加到Laravel中。打开config/app.php并找到aliases键,添加
提供者
brunaobh\Search\Search\SearchServiceProvider::class,
别名
brunaobh\Search\Search\SearchServiceProvider::class,
'Search' => brunaobh\Search\Facades\Search::class,
联系方式
Bruno Coelho brunaobh@gmail.com
许可协议
本项目采用MIT许可协议分发。有关更多信息,请参阅[LICENSE][LICENSE.md]。