patinthehat/laravel-repositories

v1.0.1 2017-04-01 17:30 UTC

This package is not auto-updated.

Last update: 2024-09-29 01:17:41 UTC


README

此包为 Laravel 5+ 提供了一个基本的仓库模式实现。

安装

可以使用 composer 安装此包

composer require patinthehat/laravel-repositories

使用

扩展 Repository 类并定义其 model 方法来创建该模型的仓库

use Permafrost\Repository;

class UserRepository extends Repository
{
    public static function model()
    {
        return 'App\\User';
    }
}

然后可以使用仓库

  $user = UserRepository::findByFirstName('john');

动态查找方法

Repository 类允许动态调用 findByN/findAllByN 方法,这将搜索仓库模型字段 N 的第一个参数。例如,

    UserRepository::findByFirstName('john')

结果是调用

    User::where('first_name', 'john')->first()

许可证

此包是开源软件,可在 MIT 许可证下使用。更多信息请参阅 LICENSE