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是审核记录内容
  • 相关阅读:
    linux下使用OpenCV的一些问题
    Google Colab调用cv2.imshow奔溃
    [LeetCode] Word Search
    信号
    信号
    [Leetcode] Subsets
    [LeetCode] Combinations
    [LeetCode] Minimum Window Substring
    [LeetCode] Set Matrix Zeroes
    sigaction 函数
  • 原文地址:https://www.cnblogs.com/mouseleo/p/9180742.html
Copyright © 2011-2022 走看看