承接 gridprinciples/repository 相关项目开发

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

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

gridprinciples/repository

最新稳定版本:0.1.1

Composer 安装命令:

composer require gridprinciples/repository

包简介

README 文档

README

A basic Eloquent Repository for Laravel 5.1.

Installation

  1. Run composer require gridprinciples/repository from your project directory.

  2. Add the following to the providers array in config/app.php:

    GridPrinciples\Repository\RepositoryServiceProvider::class,
  3. Make a Repositories folder somewhere in your application, such as app/Repositories.

Usage

  1. Make a new Repository by extending GridPrinciples\Repository:

    <?php
    
    namespace App\Repositories;
    
    use GridPrinciples\EloquentRepository;
    
    class FooRepository extends EloquentRepository {
        protected static $model = \App\Foo::class;
    }
  2. (Recommended) Use your repository in your controller(s):

    <?php
    
    namespace App\Http\Controllers;
    
    use App\Repositories\FooRepository;
    
    public function __construct(FooRepository $repository)
    {
        $this->repository = $repository;
    }
    
    public function somePage($id)
    {
        $model = $this->repository->get($id);
    
        if(!$model) {
            // Model not found.
            return abort(404);
        }
    
        return view('my_view', [
            'foo' => $model,
        ]);
    }

Some basic CRUD functionality is included with the EloquentRepository:

Creating

You can call save with an array of data in order to make a new model/record.

$newModel = $this->repository->save([
    'title' => 'This is indicative of a title',
    'description' => 'You might have a description field, perhaps.',
]);

It is recommended you populate your model's $fillable array in order to avoid mass-assignment problems.

Reading

You can select one or many records by their keys (usually id) using get:

$singleModel = $this->repository->get(1);
$multipleModels = $this->repository->get([2, 3, 4]);

If you'd like to retrieve many models and paginate them, use the index method:

$pageOfModels = $this->repository->index(10); // 10 records per page

Updating

You can update models in a very similar way as creating, also by using the save method:

$data = [
    'status' => 'active',
];
$id = 1;

$this->repository->save($data, $id);

You can also pass an array of keys as the second argument to save in order to update many records at once.

Deleting

Deleting models can be accomplished easily using the delete method:

$this->repository->delete($id);

You can also pass an array of keys to delete in order to delete many records at once.

License

This is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-09-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固