定制 inquiloper/laravel-baserepository 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

inquiloper/laravel-baserepository

Composer 安装命令:

composer require inquiloper/laravel-baserepository

包简介

A base repository that wraps some of laravel eloquent's functionality so you can share it among your own repositories.

README 文档

README

Laravel Base Repository

Description

A wrapper around eloquent's main features so you can share them among your own repositories

Installation

In order to install this package, all you have to do is execute the following line in your console composer require inquiloper/laravel-baserepository

Then in your repositories

    use Inquiloper\BaseRepository;
    use App\User;
    class UsersRepository extends from BaseRepository implements UsersRepositoryInterface {

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

That's it, you're ready to rock now!

Documentation

Let's suppose you have this function in your controller where you type-hint your repo

public function users(UsersRepositoryInterface $usersRepo){}

Now, the methods you have available are:

Find all elements of the model

$usersRepo->findAll()

Find one element by $field

$usersRepo->findOneBy(Array $fields)

Find All elements by $fields

$usersRepo->findAllBy(Array $fields)

Create and save to the DB

$usersRepo->create(Array $data)

Update with $data by $fields

$usersRepo->updateBy(Array $fields, Array $data) public function with($relationships);

Update with $data by $fields

$usersRepo->updateBy(Array $fields, Array $data)

Delete by $fields

$usersRepo->deleteBy(Array $fields)

Eager-load relationships

$usersRepo->with(['posts', 'comments'])->findOneBy(['id' => 1])

Dynamic methods

You can call the findOneBy method with a dynamic name like so:

$usersRepo->findOneByName('John Doe')

This will translate to select * from users where name = 'John Doe' limit 1

The dynamic calling will automatically snake_case anything after findOneBy , so Name converts to name, UserEmail to user_email and so on. You can turn this off and the method will add the where clause with the literal name

$usersRepo->findOneByWpEmail('email@example.com' , false)

This will translate to select * from users where WpEmail = 'email@example.com' limit 1

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固