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()) { ...
随机推荐
- 【Linux】CentOS7 上使用yum安装和卸载软件【yum安装wine举例】
关于yum的相关解释,请 man yum 自行查看. 配置常用源:http://www.cnblogs.com/sxdcgaq8080/p/7516186.html yum的使用类似于在windows ...
- JAVA常见算法题(十九)
package com.xiaowu.demo; /** * * 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和. * * * @author WQ ...
- Python命令行参数学习
man python 查看python的帮助文件 命令行参数: -B Don't write .py[co] files on import. See a ...
- httpd.conf详细解释
httpd.conf详解 http://www.php100.com/html/webkaifa/apache/2009/0418/1192.html
- MySql中LongText字段对应Hibernate映射文件的设置(转)
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...
- Qt creator发布可执行文件方式----靠谱
1.首先用 QtCreator 新建一个 Qt Widgets Application 项目,直接用默认的 QMainWindow 程序就可以了,项目名字假定是serial_port.exe. 然后以 ...
- 【LeetCode-面试算法经典-Java实现】【109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)】
[109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 ...
- 百度地图 Android SDK - 标注(Marker)的基本使用
标注(Marker)是开发人员最常使用的地图覆盖物志一.今天就来向大家介绍一些标注(Marker)的最基本用法! 实现目标: 1.构建基础地图页面: 2.在地图的中心点处加入 Marker: 3.实现 ...
- [GraphQL] Query a GraphQL API with graphql-request
To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation ...
- Php函数之end
Php函数之end end()函数 (PHP 4, PHP 5, PHP 7) end - 将数组的内部指针指向最后一个单元 说明 mixed end ( array &$array ) en ...