omatech / lars
v1.0.5
2024-05-24 11:09 UTC
Requires
- php: ^7.1|^7.2|^7.3|^7.4|^8.0
- illuminate/support: 5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
This package is auto-updated.
Last update: 2024-09-24 14:37:22 UTC
README
LARS 抽象数据层,使其易于维护。
安装
您可以通过composer安装此包
composer require omatech/lars
使用方法
创建自己的仓库类,继承BaseRepository类,使用model函数为仓库设置eloquent模型。
class Repository extends BaseRepository { public function model() : String { return Model::class; } }
现在您可以使用查询构建器轻松创建自己的函数。
public function method() { return $this->query() ->get(); }
条件
创建一个实现CriteriaInterface接口的条件。使用apply函数,您可以根据自己的条件进行过滤。
public class Criteria implements CriteriaInterface { public function apply(Builder $q) : Builder { return $q->where('role', 'admin'); } }
使用您的条件
public function method() { return $this->pushCriteria(new FooCriteria) ->query() ->get(); }
列出应用的条件
public function method() { return $this->getCriterias(); }
删除一个应用的条件
public function method() { return $this->pushCriteria(new FooCriteria) ->popCriteria(new FooCriteria) ->query() ->get(); }
删除所有应用的条件
public function method() { return $this->pushCriteria(new FooCriteria) ->pushCriteria(new BarCriteria) ->resetCriteria() ->query() ->get(); }
仓库中所有方法的全局条件
您可以使用仓库的构造方法将条件应用于所有方法。
public function __construct() { $this->pushCriteria(new FooCriteria); }
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全
如果您发现任何与安全相关的问题,请通过电子邮件cbohollo@omatech.com而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。