bulwark/repoman

v1.0.2 2017-12-05 13:50 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:55:13 UTC


README

Latest Version Software License Build Status Coverage Status Total Download

简介

这是 Eloquent 的一个基本仓库类,包含覆盖大多数查询的便捷方法。有助于将您的持久层与业务代码抽象化。

安装

适用于 Laravel 5.4 及以上版本

composer require bulwark/repoman ~1.0

实现

以下示例将使用一个假设的名为 User 的 Eloquent 模型。

<?php

namespace App\Repositories;

use App\Models\User;
use Bulwark\Repoman\Repository;

class UserRepository extends Repository
{
    protected function getModel()
    {
        return new User;
    }
}

选项

Repoman 已与 Bulwark\Dream 集成。有关更多信息,请参阅 Dream 文档。所有 get 方法提供的 $options 键采用以下格式

注意:如果您使用 Dream 的控制器,它将自动解析请求的查询字符串为正确格式。

API

以下示例将使用一个假设的名为 User 的 Eloquent 模型。

get (array $options = [])

获取所有 User

getById ($id, array $options = [])

通过主键获取一个 User

getRecent (array $options = [])

created_at 降序获取 User

getRecentWhere (string $column, mixed $value, array $options = [])

created_at 降序获取 $column=$valueUser

getWhere (string $column, mixed $value, array $options = [])

获取 $column=$valueUser

getWhereArray (array $clauses, array $options = [])

通过多个 where 子句获取 User 行 ([$column1 => $value1, $column2 => $value2])

getWhereIn (string $column, array $values, array $options = [])

获取 $column 可以是 $values 中任何一个值的 User

getLatest (array $options = [])

获取最新的 User

getLatestWhere (string $column, mixed $value, array $options = [])

获取 $column=$value 的最新 User

delete ($id)

通过主键删除 User

deleteWhere ($column, $value)

删除 $column=$valueUser

标准

此软件包符合 PSR-1PSR-2PSR-4。如果您发现合规性问题,请通过 pull request 提交补丁。

测试

$ phpunit

贡献

有关详细信息,请参阅 CONTRIBUTING

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件