aubinlrx/laravelrepositories 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

aubinlrx/laravelrepositories

最新稳定版本:0.1.5

Composer 安装命令:

composer require aubinlrx/laravelrepositories

包简介

Laravel Repositories

README 文档

README

Repository Pattern for Laravel 5 with Eloquent ORM

Version: 0.1.5

Filterable Trait

Handy method to filter query

Usages

<?php

use AubinLrx\LaravelRepositories\Repository;
use AubinLrx\LaravelRepositories\Traits\FilterableTrait;

class BookRepository extends Repository {

   use FilterableTrait;
   
   /**
    * The fields that are filterable
    * @var array
    */
   protected $filterable = ['author_id', 'date_range'];

   public function getAllWithFilter() {
      return $this->applyFilterToQuery( $this->model->query() )->all(); 
   }

   public function filterByDateRange($query, $value) {
        return $query->whereBetween('date', $value);
   }

   public function filterBy($field, $value) {
        $this->addFilter($field, $value);
        return $this;
   }

}

class BookController extends Controller {

    public function __construct(BookRepository $books) 
    {
        $this->books = $books;
    }

    public function index(Request $request) 
    {
        $books = $this->books->filterBy('date_range', $request->only(['str_date', 'end_date']))
           ->filterBy('author_id', $request->only('author_id'))
           ->getAllWithFilter();

        return view('books.index', compact('books'));
    }

}

?>

Release Logs

v0.1.5

  • bug fix: Laravel 5.1 create method
  • feature: Add findOrFail method

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-24