承接 koalabs/repo 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

koalabs/repo

Composer 安装命令:

composer require koalabs/repo

包简介

Simple implementation of the Repository Interface for Eloquent with the most basic CRUD methods

关键字:

README 文档

README

Simple implementation of the Repository Interface for Eloquent with the most basic CRUD methods.

If you find yourself implementing the same default methods over an over again for every new repository class you create, this package could save you some time.

Quick overview

Repo consists of two basic files:

  • RepoInterface.php (Interface)
  • Repo.php
  • CacheableRepo.php

Repo.php

The Repo.php file is just an interface with the basic CRUD methods (Create, Read, Update, Destroy). It will enforce you implement all methods should you choose to use some other kind of Repository in the future.

EloquentRepo.php

The EloquentRepo.php file is an Eloquent implementation of the Repo interface. Keep reading to find out how I intend to use it.

Install

In your application's root directory, open up the composer.json file and add the package to the require section so it looks like this:

"require": {
    "koalabs/repo": "dev-master"
},

Open the command line, and in the root ot our application, run the Composer update like this:

php composer.phar update

Now let's add the Repo Service Provider. Open the app/config/app.php file and in the providers array, add the following line:

'Koalabs\Repo\RepoServiceProvider'

Usage

You have at your disposal a simple repository class that handles eloquent entities (models). Every new repository you create will simply be an extension of the EloquenRepository. Here is an example:

use Koalabs\Repo\Repo;

class UserRepository extends Repo {

    protected $relations = ['role'];

    public function __construct(User $entity)
    {
        parent::__construct($entity);
    }
}

The only thing you have to do for the child repository class is tell the repository which Eloquent model/entity (in this case, User) it should manage. You'll then be able to use default methods for finding, creating, storing, and deleting the specified model. With that you should be good to go, but dive into the package's code for a better grasp at what's happening under the hoods.

Available methods

You'll have these basic CRUD methods at your disposal:

  • findById($id)
  • findByField($field, $value)
  • all($orderBy)
  • create(array $fields)
  • update($id, array $fields)
  • destroy($id)

Cacheable Repos

There's the added option to use a basic filesystem cache with your repos. Simply extend the CacheableRepo class instead of the Repo and you'll be good to go.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固