推荐一个laravel极速完成增删改查的第三方包

发布时间:2024-12-09 点击:86
下面由laravel教程栏目给大家推荐一个laravel极速完成增删改查的第三方包,希望对需要的朋友有所帮助!
推荐一个实用的laravel包https://github.com/osindex/laravelcontrollertrait
可以通过命令行直接生成model、controller和migrate文件,并且添加了很多常用的筛选过滤方法,不到一分钟就能写完简单的增删改查
特别是对查询的优化,基本不用单独加接口
laravel-controller-trait
install
composer require osi/laravel-controller-traituseage
###artisan
php artisan trait:controllerphp artisan trait:model###controller&&route
use osi\\\\laravelcontrollertrait\\\\traits\\\\controllerbasetrait; // traituse app\\\\admin; //model fileclass adminscontroller extends controller{ use controllerbasetrait; public function __construct(admin $model) { $this->model = $model; $this->resource = '\\\\osi\\\\laravelcontrollertrait\\\\resources\\\\resource'; $this->collection = '\\\\osi\\\\laravelcontrollertrait\\\\resources\\\\collection'; $this->functions = get_class_methods(self::class); }}route::resources(['admins' => 'adminscontroller']);#以上完成,即提供了常规的增删改查方法#【1.10】新增批量更新post:api/admins/batchrequest()->all(): [ ['id'=>1,'field'=>'xxx','field2'=>xxx], ['id'=>2,'field'=>'x2x','field2'=>x2x]]#【1.11】剥离基础返回类use osi\\\\laravelcontrollertrait\\\\traits\\\\responsebasetrait; // trait 附带以下方法datasuccesscreatedacceptednocontentbadrequestunauthorizedforbiddenunprocesableetitysuccessfilter
/message?filter={"created_at":{"from":"2016-02-20","to":"2016-02-24 23:59:59"}, "id":{"operation":"not in", "value":[2,3,4]}}/message?filter={"user_id":{"operation":"in", "value":[null,2,3,4]}}/message?filter={"id":{"from":2,"to":5}}/message?filter={"id":{"to":5}} or /message?filter={"id":{"operation":"<=","value":5}}/message?filter={"updated_at":{"isnull":true}}/message?filter={"answer":{"operation":"like","value":"partial search string"}}/message?filter={"answer":"full search string"}/message?filter={"user.name":"asd"} # 关联搜索 wherehas/message?filter={"id":1}# 暂时只支持单字段排序/message?sort=id/message?sort=-id/message?sort=user.name# 关联搜索/message?expand=user response: { "id": 1, "message": "some message", "user_id": 1, ... "user": { "id": 1, "name": "some username", ... } }# 关联搜索子集,获取特定字段/message?expand=archives,user.recordable:id/status# 【1.8】新增scope搜索//user model<?php新增允许的filterscopes属性protected $filterscopes = ['querylike'];// laravel实现姓名或电话搜索public function scopequerylike($query, $param){ return $query->where(function ($querysec) use ($param) { return $querysec->where('name', 'like', '%' . $param . '%')->orwhere('phone', 'like', '%' . $param . '%'); });}/user?filter={"querylike":2333}# 【1.9】新增json搜索(jsoncontains,jsonlength) ##注:目前仅有jsonlength 支持type属性/message?filter={"json->parama":"233"}/message?filter={"json->array":{"operation":"jsonlength","type":">","value":5}}/message?filter={"json->array":{"operation":"jsoncontains","value":5}}# 【1.11】 filterexpand 用法## 一般我们使用expand对应with方法 如 `model->with('app')` === `?expand=app`因此 可以使用 filterexpand 完成 `model->with(['app'=>function($q) use($id){$q->where('id',$id)}])` 的类似方法/message?expand=app&filterexpand={'app.created_at': { 'operation': '>=', 'value': 'now()' },'app.id�

干货分享,商标转让具有哪些优势呢?
电脑使用IE浏览器下载文件完成后没有提示如何解决
错误查询超时已过期行速度解决好几次了
电脑运行外挂软件提示.NET初始化错误如何解决
阿里云怎么查看服务器备案号
融资过后 这家币圈平台启用极品二数字域名!
创业者进行购买外卖系统时应注意什么
Docker监控——Prometheus