Lumen Repository(仓储)
在 Laravel 5 中使用 Repository 模式实现业务逻辑和数据访问的分离:http://laravelacademy.org/post/3063.html
Eloquent: 集合:https://d.laravel-china.org/docs/5.3/eloquent-collections
集合:https://d.laravel-china.org/docs/5.3/collections
Laravel & Lumen之Eloquent ORM使用速查-基础部分:https://segmentfault.com/a/1190000005792671
Laravel & Lumen之Eloquent ORM使用速查-进阶部分:https://segmentfault.com/a/1190000005792708
Laravel & Lumen之Eloquent ORM使用速查-高级部分:https://segmentfault.com/a/1190000005792734
Lumen 进阶之数据库交互,Eloquent ORM,Facades,Collection:http://blog.gxxsite.com/lumen-advance-database-interaction/
github链接:https://github.com/andersao/l5-repository
简书这篇讲得很透彻:https://www.jianshu.com/p/dcaaf801c294
这篇也很不错:http://oomusou.io/laravel/laravel-architecture/
实例讲解
先通过migrations建user_log表之后,
使用migrations:http://www.cnblogs.com/cxscode/p/8371789.html
运行下面语句
php artisan make:repository UserLog
此时会创建:
app/Models/UserLog.php //对应Model
app/Repositories/UserLogRepository.php //对应仓储类接口
app/Repositories/UserLogRepositoryEloquent.php //对应仓储类
app/Models/UserLog.php
class UserLog extends Model implements Transformable
{
use TransformableTrait; /**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
// 'id',
'user_id',
'status',
'type',
// 'deleted_at',
// 'created_at',
// 'updated_at',
]; protected $table = 'user_log'; protected $primaryKey = 'id'; }
$fillable默认是空数组,需要补填一些增删改查要操作的字段,$table(表名)和$primaryKey(主键)一般没有,最好自己补全一下
app/Repositories/UserLogRepository.php
interface UserLogRepository extends RepositoryInterface
{
//
}
一般也是一个空接口,可以根据需求加入需要实现的接口
app/Repositories/UserLogRepositoryEloquent.php
class UserLogRepositoryEloquent extends BaseRepository implements AddressRepository
{
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return Address::class;
} /**
* Boot up the repository, pushing criteria
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
} }
默认有一个model获取方法和一个boot启动方法,可以把仓储做为控制器和Model的中间层,可以实现一些方法,控制器调仓储,仓储调Model
Lumen Repository(仓储)的更多相关文章
- Repository 仓储,你的归宿究竟在哪?(三)-SELECT 某某某。。。
写在前面 首先,本篇博文主要包含两个主题: 领域服务中使用仓储 SELECT 某某某(有点晕?请看下面.) 上一篇:Repository 仓储,你的归宿究竟在哪?(二)-这样的应用层代码,你能接受吗? ...
- Repository 仓储,你的归宿究竟在哪?(二)-这样的应用层代码,你能接受吗?
写在前面 关于"Repository 仓储,你的归宿究竟在哪?"这个系列,本来是想写个上下篇,但是现在觉得,很有多东西需要明确,我也不知道接下来会写多少篇,所以上一篇的标题就改成了 ...
- Repository仓储 UnitofWork
Repository仓储 UnitofWork 目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 本章我们来创建仓储类Repository 并且引入 UnitOfWork 我对 ...
- Repository 仓储
Repository 仓储 写在前面 首先,本篇博文主要包含两个主题: 领域服务中使用仓储 SELECT 某某某(有点晕?请看下面.) 上一篇:Repository 仓储,你的归宿究竟在哪?(二)-这 ...
- Repository 仓储,你的归宿究竟在哪?(上)
Repository 仓储,你的归宿究竟在哪?(上) 写在前面 写这篇博文的灵感来自<如何开始DDD(完)>,很感谢young.han兄这几天的坚持,陆陆续续写了几篇有关于领域驱动设计的博 ...
- 【无私分享:ASP.NET CORE 项目实战(第五章)】Repository仓储 UnitofWork
目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 本章我们来创建仓储类Repository 并且引入 UnitOfWork 我对UnitOfWork的一些理解 UnitOfW ...
- Repository 仓储,你的归宿究竟在哪?(一)-仓储的概念
写在前面 写这篇博文的灵感来自<如何开始DDD(完)>,很感谢young.han兄这几天的坚持,陆陆续续写了几篇有关于领域驱动设计的博文,让园中再次刮了一阵"DDD探讨风&quo ...
- MVC+Ef项目(2) 如何更改项目的生成顺序;数据库访问层Repository仓储层的实现
我们现在先来看看数据库的生成顺序 居然是 Idal层排在第一,而 web层在第二,model层反而在第三 了 我们需要把 coomon 公用层放在第一,Model层放在第二,接下来是 Idal ...
- 从Entity Framework的实现方式来看DDD中的repository仓储模式运用
一:最普通的数据库操作 static void Main(string[] args) { using (SchoolDBEntities db = new SchoolDBEntities()) { ...
随机推荐
- java实现随机中文
原文:http://blog.csdn.net/u013926110/article/details/44600601 public class CreateCheckCode { /** * 生成随 ...
- CSS的7种常用的垂直居中的方法
1.绝对定位上下百分之五十然后上外边距做外边距都是他的宽高的一半 #child{ width: 200px; height: 150px; position: absolute; left: 50%; ...
- 联想台式机启天m4350 启用intel vt-x
在vmware workstations10 64位上安装windows server 2012操作系统时,出现例如以下错误: 已将该虚拟机配置为使用 64 位客户机操作系统.可是,无法运行 64 位 ...
- jar文件的Eclipse插件安装
以[zigen.plugin.db_1.2.2.v20101009.jar]为例. (1)在[\eclipse\dropins]目录下新建一个目录,例如[myplugin] (2)上面新建的n目录下建 ...
- 解决The prefix 'context' for element 'context:component-scan' is not bound
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- postman(一)批量执行接口测试用例
postman(一)批量执行接口测试用例 学习了:https://blog.csdn.net/github_36032947/article/details/78611405 还可以把collecti ...
- [Algorithm] Maximum Contiguous Subarray algorithm implementation using TypeScript / JavaScript
Naive solution for this problem would be caluclate all the possible combinations: const numbers = [1 ...
- Linux中MySQL数据库max_allowed_packet的调整
在MySQL数据库里某表有一个blob字段,当上传文件超过1M的时候出现下面的错误: PreparedStatementCallback; SQL [insert into uos.docfile(r ...
- 【转载】json对象的使用
使用JSON 进行数据传输 一.选择的意义 在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.为了更好的使用ajax, 我们将学习一种有用的数据格式 JavaScript O ...
- HTML 5 音频Audio
在HTML5标准网页里面,我们能够运用audio标签来完毕我们对声音的调用及播放. 下面是最常常见到的运用HTML5三种基本格式: 1.最少的代码 <audio src="song.o ...