prettus/l5-repository笔记

单词必备

  • repository 存储库
  • Contracts 合同(==契约==)
  • criteria ==标准==;(评判或作决定的)准则;原则

1.安装

1.1.Composer

执行以下命令以获取包的最新版本:
composer require prettus/l5-repository

1.2.Laravel

1.2.1.>= laravel5.5

ServiceProvider将自动附加

1.2.2.其他

  • config/app.php中,将Prettus\Repository\Providers\RepositoryServiceProvider::class添加到Providers数组的末尾:
    'providers' => [
    ...
    Prettus\Repository\Providers\RepositoryServiceProvider::class,
    ],
  • Lumen
    $app->register(Prettus\Repository\Providers\LumenRepositoryServiceProvider::class);
  • 发布配置
    php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"

2.方法

2.1.Prettus\Repository\Contracts\RepositoryInterface

  • all($columns = array(‘*’))

  • first($columns = array(‘*’))

  • paginate($limit = null, $columns = [‘*’])

  • find($id, $columns = [‘*’])

  • findByField($field, $value, $columns = [‘*’])

  • findWhere(array $where, $columns = [‘*’])

  • findWhereIn($field, array $where, $columns = [*])

  • findWhereNotIn($field, array $where, $columns = [*])

  • findWhereBetween($field, array $where, $columns = [*])

  • create(array $attributes)

  • update(array $attributes, $id)

  • updateOrCreate(array $attributes, array $values = [])

  • delete($id)

  • deleteWhere(array $where)

  • orderBy($column, $direction = ‘asc’);

  • with(array $relations);

  • has(string $relation);

  • whereHas(string $relation, closure $closure);

  • hidden(array $fields);

  • visible(array $fields);

  • scopeQuery(Closure $scope);

  • getFieldsSearchable();

  • setPresenter($presenter);

  • skipPresenter($status = true);

    2.2.Prettus\Repository\Contracts\RepositoryCriteriaInterface

  • pushCriteria($criteria)

  • popCriteria($criteria)

  • getCriteria()

  • getByCriteria(CriteriaInterface $criteria)

  • skipCriteria($status = true)

  • getFieldsSearchable()

2.3.Prettus\Repository\Contracts\CacheableInterface

  • setCacheRepository(CacheRepository $repository)
  • getCacheRepository()
  • getCacheKey($method, $args = null)
  • getCacheMinutes()
  • skipCache($status = true)

2.4.Prettus\Repository\Contracts\PresenterInterface

  • present($data);

2.5.Prettus\Repository\Contracts\Presentable

  • setPresenter(PresenterInterface $presenter);
  • presenter();

2.6.Prettus\Repository\Contracts\CriteriaInterface

  • apply($model, RepositoryInterface $repository);

2.7.Prettus\Repository\Contracts\Transformable

  • transform();
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 4

@wangu7 搬运一遍,就是学习一遍 ,做个笔记

2年前 评论

@❤seven 有空的时候,你研究下,我自己感觉这个不孬,能学到很多

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!