pieterdev/repoflow

一个简单的特性,允许以优雅的模型流畅地查询仓库。在一定程度上提供了优雅的灵活性,同时在哪些方法由仓库支持方面保持明确。

1.0.5 2014-08-12 16:25 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:57:47 UTC


README

一个简单的特性,允许以优雅的模型流畅地查询仓库。在一定程度上提供了优雅的灵活性,同时在哪些方法由仓库支持方面保持明确。

使用方法

简单

  1. 将 Pieterdev\Repoflow\FluentRepositoryTrait 添加到您的仓库类中。
  2. 在您的仓库类中添加一个 protected static $filters= [...] 数组,表示您的模型上哪些属性应该是可过滤的。
  3. 在您的仓库类中,使用名为 $model 的字段作为您仓库使用的模型,或者使 $model 是一个包含仓库使用的 eloquent 模型名称的字符串。
  4. 然后您可以对您的仓库进行链式查询,例如 `$repo->whereName('Jack')->whereScore(3)->all();`
  5. all() 方法调用查询。
<?php

class SomeEloquentRepository implements ISomeRepository {

    use Pieterdev\Repoflow\FluentRepositoryTrait;

    protected static $filters = [
        'name',
        'score'
    ];

    protected $model;

    function __construct(User $userModel) 
    {
        $this->model = $userModel;
    }
}