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里的数据操作剥离出来,这样做有几个好处: 把数据处理逻辑 ...
随机推荐
- Thinkpad x230i安装Ubuntu10.04发生no network devices available
这个是由于10.04版本没有集成x230i的网卡驱动导致,需要到http://sourceforge.net/projects/e1000/f ... %20stable/下载最新版本驱动,并安装,之 ...
- bzoj 1040: [ZJOI2008]骑士【基环树+树形dp】
没考虑可以连着两个不选--直接染色了 实际上是基环森林,对于每棵基环树,dfs找出一个环边,然后断掉这条边,分别对这条边的两端点做一边treedp,取max加进答案里 treedp是设f[u]为选u点 ...
- bzoj 1502 月下柠檬树【Simpson积分】
投影到地面之后,会发现圆形在平行光下面积和形状是不会变的,也就是所要求的图形是若干个圆和把相邻两个圆连起来的公切线所组成的. 公切线和圆间距瞎求一下就行,注意要去掉被完全覆盖的圆 然后simpson即 ...
- RabbitMQ学习之HelloWorld(1)
RabbitMQ就是一个消息代理(message broker),可以用来接收和发送消息. 消息队列有一些黑话,我们来看下: Producer : 发送message的程序 Queue : 可以用来存 ...
- shiro之IniRealm
Shiro认证过程 创建SecurityManager--->主体提交认证--->SecurityManager认证--->Authenticsto认证--->Realm验证 ...
- php 打包下载
<?php class zipfile { var $datasec = array (); var $ctrl_dir = array (); var $eof_ctrl_dir = &quo ...
- 在xampp集成环境下使用 thinkphp 连接oracle
今天搞了大半天,终于成功了. 1. 首先需要让xampp支持oracle,直接按这个网页上说的做就行.http://nimal.info/blog/2009/activate-oracle-on-xa ...
- ROS学习笔记六:xxx.launch文件详解
每当我们需要运行一个ROS节点或工具时,都需要打开一个新的终端运行一个命令.当系统中的节点数量不断增加时,每个节点一个终端的模式会变得非常麻烦.那么有没有一种方式可以一次性启动所有节点呢?答案当然是肯 ...
- [Usaco2006 Jan] Dollar Dayz 奶牛商店
Description 约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,-,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢? Inpu ...
- IOS 绘制PDF -转
-(void)createPdf:(UIImage *)img andText:(NSString *)text{ NSArray *paths = NSSearchPathForDirectorie ...