zoukankan      html  css  js  c++  java
  • Laravel 多态关联使用的案例

    1.实现的功能,:短信发送,需要签名和模板审核,审核结果要插进审核记录表

    2,在signature(签名表模型)和 template(模板表模型)添加多态对应关系代码其实一样,代码如下:

    审核记录表需要有:auditable_type, 用来保存所属模型的类名.该字段可默认插入值,也可自定义
    A:在审核记录表添加
    public function auditable()     {         return $this->morphTo();     }
    
    B:在签名表加
    public function audite()     {         return $this->morphMany('AppAuditRecord', 'auditable');     }
    C:在模板表模型
    public function audite()     {         return $this->morphMany('AppAuditRecord', 'auditable');     }
    3.添加完对应关系之后就可以简单使用了:例如
      $template=Template::whereIn('id', $id)->get();   $template->audite()->save($auditRecord);//$auditRecord是审核记录内容
  • 相关阅读:
    poj 2029 Get Many Persimmon Trees 夜
    poj 1191 棋盘分割 夜
    DOM (四)
    div拖拽, onmousedown ,onmousemove, onmouseup
    闭包理解
    DOM(一)
    内存溢出与内存泄漏
    div随鼠标移动而移动(滚动条)
    对象继承模式
    DOM(二)
  • 原文地址:https://www.cnblogs.com/mouseleo/p/9180742.html
Copyright © 2011-2022 走看看