1:创建模型

2:定义关联模型

<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;
class TypeModel extends Model
{
use SoftDelete;
//链接pyg商品类型表
protected $table = 'pyg_type';// 进行和规格模型关联,1对多
public function spec()
{
return $this->hasMany('Spec', 'type_id', 'id');
}
// 进行和属性模型进行关联
public function attribute()
{
return $this->hasMany('Attribute', 'type_id', 'id'); }

3:定义规格名称和规格值   规格名和规格值一对多

<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;
class Spec extends Model
{
//
use SoftDelete;
protected $table = 'pyg_spec';
//关联规格和规格值 一个规格对应多个规格值
public function specValue()
{
return $this->hasMany('SpecValue', 'spec_id', 'id');
}

4:控制器代码:

    public function read($id)
{
//商品模型详情
// 验证参数
if (!intval($id)) {
return json(['code' => 500, 'message' => 'id参数不正确']);
}
// 数据库处理
$res = TypeModel::with('spec,attribute,spec.specValue')->find(16);
// print_r(collection($res)->toArray());
return json(['code' => 200, 'message' => '商品详情展示', 'data' => $res]);
}

5:路由:

//商品模型列表展示
Route::get('index','task/type/index');

6:效果图

最新文章

  1. #英文#品读中国城市个性——上海人的精明&amp;头啖汤
  2. Tomcat 7.0的配置
  3. 前端XSS攻击和防御
  4. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
  5. c/c++小知识
  6. POJ 2195 D - Going Home 费用流
  7. Java环境变量批处理文件
  8. 从零开始Unity3D游戏开发【3烘焙】
  9. POJ输出状态的逻辑。
  10. XJOI1595空中楼阁【最短路】
  11. linux卸载openjdk
  12. Alpha 冲刺 (3/10)
  13. redis主从复制详述
  14. P1006 传纸条-洛谷luogu-dp动态规划
  15. BZOJ1567 [JSOI2008]Blue Mary的战役地图 二分答案 哈希
  16. 系统windows版本修改
  17. Oracle 字符集更改
  18. tidb 升级步骤
  19. 【拓扑排序】BZOJ4010-[HNOI2015]菜肴制作
  20. python的学习笔记之——time模块常用内置函数

热门文章

  1. 对于fetch的理解
  2. xcode 常用插件 加快开发速度 --严焕培
  3. SSH 远程访问及控制 ( 早上好,我是派大星,上帝派来爱你的那颗星)
  4. Java产生指定范围内的随机日期
  5. c++ 聚合/POD/平凡/标准布局 介绍
  6. Solution -「集训队作业 2013」「洛谷 P4841」城市规划
  7. Solution -「洛谷 P6292」区间本质不同子串个数
  8. Note -「单位根反演」学习笔记
  9. MySQL 5.7 基于GTID主从复制+并行复制+半同步复制
  10. netty系列之:channelPipeline详解