当前位置:网站首页>laravel的模型删除后动作
laravel的模型删除后动作
2022-07-01 15:46:00 【精哥哥】
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
// use App\Models\OrderGoods;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
use HasDateTimeFormatter;
public $primaryKey = 'order_id';
// 数据库'database_test'中的test表
public $table = 'order';
public $timestamps = false;
protected $connection = 'baixiao';
/**
* 删除
*/
public static function boot()
{
parent::boot();
static::deleted(function ($model) {
//这样可以拿到当前操作id
$order_id = $model->order_id;
if ($order_id) {
OrderGoods::where('order_id', $order_id)->delete();
}
});
}
}
删除订单表的数据后,我们如果还需要删除订单商品表,可以在order的模型中,加入这个
就是删除订单后,继续删除订单商品
边栏推荐
- 张驰咨询:锂电池导入六西格玛咨询降低电池容量衰减
- Redis seckill demo
- 大龄测试/开发程序员该何去何从?是否会被时代抛弃?
- [STM32 learning] w25qxx automatic judgment capacity detection based on STM32 USB storage device
- 药品溯源夯实安全大堤
- 新出生的机器狗,打滚1小时后自己掌握走路,吴恩达开山大弟子最新成果
- STM32F1与STM32CubeIDE编程实例-PWM驱动蜂鸣器生产旋律
- Qt+pcl Chapter 6 point cloud registration ICP series 4
- Reading notes of top performance version 2 (V) -- file system monitoring
- 将ABAP On-Premises系统连接到中央检查系统以进行自定义代码迁移
猜你喜欢
她就是那个「别人家的HR」|ONES 人物
Summary of point cloud reconstruction methods I (pcl-cgal)
ATSS:自动选择样本,消除Anchor based和Anchor free物体检测方法之间的差别
Overview | slam of laser and vision fusion
[target tracking] |stark
HR interview: the most common interview questions and technical answers
Pico, can we save consumer VR?
Returning to the top of the list, the ID is still weak
Programming examples of stm32f1 and stm32subeide - production melody of PWM driven buzzer
Redis high availability principle
随机推荐
#夏日挑战赛# HarmonyOS canvas实现时钟
ATSs: automatically select samples to eliminate the difference between anchor based and anchor free object detection methods
u本位合约和币本位合约有区别,u本位合约会爆仓吗
Comment win11 définit - il les permissions de l'utilisateur? Win11 comment définir les permissions de l'utilisateur
Detailed explanation of stm32adc analog / digital conversion
[one day learning awk] function and user-defined function
二叉树的前序,中序,后续(非递归版本)
Raytheon technology rushes to the Beijing stock exchange and plans to raise 540million yuan
三星率先投产3nm芯片,上海应届硕士生可直接落户,南开成立芯片科学中心,今日更多大新闻在此...
What is the forkjoin framework in the concurrent programming series?
Qt+pcl Chapter 6 point cloud registration ICP series 4
搜索框和按钮缩放时会有缝隙的bug
电脑照片尺寸如何调整成自己想要的
精益六西格玛项目辅导咨询:集中辅导和点对点辅导两种方式
TensorFlow團隊:我們沒被拋弃
说明 | 华为云云商店「商品推荐榜」
MySQL advanced 4
[pyGame practice] do you think it's magical? Pac Man + cutting fruit combine to create a new game you haven't played! (source code attached)
使用 csv 导入的方式在 SAP S/4HANA 里创建 employee 数据
Zhang Chi's class: several types and differences of Six Sigma data