l5-repository基本使用
一、安装
composer require prettus/l5-repository

二、Model层:Warehouse.php
<?php namespace App\Model; use Illuminate\Database\Eloquent\Model; class Warehouse extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
protected $table = "supplier_warehouse";
protected $primaryKey = 'g_w_id';
public $timestamps = false;
}
三、仓库的两个文件:
3.1、文件及位置

3.2、WarehouseRepository.php:
<?php namespace App\Repositories; use Prettus\Repository\Contracts\RepositoryInterface; /**
* Interface ShopRepository.
*
* @package namespace App\Repositories;
*/
interface WarehouseRepository extends RepositoryInterface
{
public function getIdsByCmpId($cmpId, $sel);
public function getNameById($g_w_id, $sel);
}
3.3、WarehouseRepositoryEloquent.php:
<?php namespace App\Repositories; use App\Model\Warehouse;
use Illuminate\Support\Facades\DB;
use Prettus\Repository\Eloquent\BaseRepository; /**
* Class ShopRepositoryEloquent.
*
* @package namespace App\Repositories;
*/
class WarehouseRepositoryEloquent extends BaseRepository implements WarehouseRepository
{
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return Warehouse::class;
} public function getIdsByCmpId($cmpId, $sel)
{
return $this->model
->select(DB::raw(implode(',',$sel)))
->where('company_id',$cmpId)
->get();
} public function getNameById($g_w_id, $sel)
{
return $this->model
->select(DB::raw(implode(',',$sel)))
->where('g_w_id',$g_w_id)
->get();
}
}
四、绑定:
4.1、文件及位置:

4.2、RepositoryServiceProvider.php:
$this->app->bind(\App\Repositories\WarehouseRepository::class, \App\Repositories\WarehouseRepositoryEloquent::class);
五、services
5.1、文件及位置:

5.2、WarehouseService.php:
<?php namespace App\Services; class WarehouseService
{
private $warehouseRepository; public function __construct($warehouseRepository)
{
$this->warehouseRepository = $warehouseRepository;
} public function getIdsByCmpId($cmpId)
{
return $this->warehouseRepository->getIdsByCmpId($cmpId, ['g_w_id']);
} public function getNameById($g_w_id)
{
return $this->warehouseRepository->getNameById($g_w_id, ['warehouse_name']);
}
}
六、控制器中调用:
6.1、文件及位置

6.2、WarehouseController.php
<?php namespace App\Http\Controllers\Warehouse; use App\Repositories\WarehouseRepository;
use App\Services\WarehouseService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller; class WarehouseController extends Controller
{
private $warehouseService; public function __construct(WarehouseRepository $warehouseRepository)
{
$this->warehouseService = new WarehouseService($warehouseRepository);
} public function test()
{
$cmpId = ;
$listWarehouse = $this->warehouseService->getIdsByCmpId($cmpId);
}
}
七、在config/app.php上加载组件:

代码:
App\Providers\RepositoryServiceProvider::class,
其他随笔l5-repository基本使用--结合使用artisan
l5-repository基本使用的更多相关文章
- DDD 领域驱动设计-谈谈 Repository、IUnitOfWork 和 IDbContext 的实践(3)
上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext 的实践(2)> 这篇文章主要是对 DDD.Sample 框架增加 Transa ...
- Asp.Net Core + Dapper + Repository 模式 + TDD 学习笔记
0x00 前言 之前一直使用的是 EF ,做了一个简单的小项目后发现 EF 的表现并不是很好,就比如联表查询,因为现在的 EF Core 也没有啥好用的分析工具,所以也不知道该怎么写 Linq 生成出 ...
- windows 部署 git 服务器报 Please make sure you have the correct access rights and the repository exists.错误
这两天在阿里云上弄windows 服务器,顺便部署了一个git服务.根据网上教程一步步操作下来,最后在 remote远程仓库的时候提示 fatal: 'yourpath/test.git' does ...
- 初探领域驱动设计(2)Repository在DDD中的应用
概述 上一篇我们算是粗略的介绍了一下DDD,我们提到了实体.值类型和领域服务,也稍微讲到了DDD中的分层结构.但这只能算是一个很简单的介绍,并且我们在上篇的末尾还留下了一些问题,其中大家讨论比较多的, ...
- Repository 仓储,你的归宿究竟在哪?(三)-SELECT 某某某。。。
写在前面 首先,本篇博文主要包含两个主题: 领域服务中使用仓储 SELECT 某某某(有点晕?请看下面.) 上一篇:Repository 仓储,你的归宿究竟在哪?(二)-这样的应用层代码,你能接受吗? ...
- Failure to find xxx in xxx was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ xxx
问题: 在linux服务器上使用maven编译war时报错: 16:41:35 [FATAL] Non-resolvable parent POM for ***: Failure to find * ...
- DDD 领域驱动设计-谈谈 Repository、IUnitOfWork 和 IDbContext 的实践(2)
上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext 的实践(1)> 阅读目录: 抽离 IRepository 并改造 Reposi ...
- 【无私分享:ASP.NET CORE 项目实战(第五章)】Repository仓储 UnitofWork
目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 本章我们来创建仓储类Repository 并且引入 UnitOfWork 我对UnitOfWork的一些理解 UnitOfW ...
- CentOS系统yum源使用报错:Error: Cannot retrieve repository metadata (repomd.xml) for repository: rpmforge.
服务器上的yum突然不好使用,使用yum的时候报错如下:[root@bastion-IDC src]# yum list......Could not retrieve mirrorlist http ...
- Laravel与Repository Pattern(仓库模式)
为什么要学习Repository Pattern(仓库模式) Repository 模式主要思想是建立一个数据操作代理层,把controller里的数据操作剥离出来,这样做有几个好处: 把数据处理逻辑 ...
随机推荐
- Linux 常用命令三 touch mkdir
一.touch命令 创建一个文件: wang@wang:~/workpalce/python$ ls wang@wang:~/workpalce/python$ .txt wang@wang:~/wo ...
- bzoj 2508: 简单题【拉格朗日乘数法】
大概是对于f(x,y)求min,先把x看成常数,然后得到关于y的一元二次方程,然后取一元二次极值把y用x表示,再把x作为未知数带回去化简,最后能得到一个一元二次的式子,每次修改这个式子的参数即可. 智 ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- 数字货币期货与现货JavaScript量化策略代码详解汇总
1.动态平衡策略 按照当前的 BTC 的价值,账户余额保留¥5000 现金和 0.1个 BTC,即现金和BTC 市值的初始比例是 1:1. 如果 BTC 的价格上涨至¥6000,即 BTC 市值大于账 ...
- NOIp 2010/Luogu P1525 关押罪犯 【二分图/并查集】 By cellur925
题目传送门 感想:相信自己的想法!继续挖掘! 读完题目后:看到的最大值最小?二分答案啊!再仔细一看:wi达到了1e9,二分可能费点劲.(其实真的是可以的)而且check函数貌似并没有什么行之有效的写法 ...
- 我的spring cloud项目历程(2018.3~2018.9)
前言 今天是9月17日,趁着山竹的临幸,得以在家里舒适的办公.项目从3月底开始,至今刚好半年.抽几十分钟,总结下半年的历程.对后面的项目,应该也有一点帮助吧. 学习前的七个问题 项目开始前,由于某些特 ...
- Qt事件系统之一:Qt中的事件处理与传递
一.简介 在Qt中,事件作为一个对象,继承自 QEvent 类,常见的有键盘事件 QKeyEvent.鼠标事件 QMouseEvent 和定时器事件 QTimerEvent 等,与 QEvent 类的 ...
- dotnetty源码解读一些要点
DefaultAttributeMap 它绑定在Channel或者ChannelHandlerContext上的一个附件. ChannelHandlerContext都是ChannelHandler和 ...
- C#DataTable学习心得[转]
一.DataSet.DataTable.DataRow.DataColumn 1] 在DataSet中添加DataTable DataSet.Tables.Add(DataTable) 实例: Dat ...
- [转]mysql事务处理用法与实例详解
转自:http://www.cnblogs.com/ymy124/p/3718439.html MySQL的事务支持不是绑定在MySQL服务器本身,而是与存储引擎相关1.MyISAM:不支持事务,用于 ...