当前位置:网站首页>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的模型中,加入这个
就是删除订单后,继续删除订单商品
边栏推荐
- MySQL backup and restore single database and single table
- 有些能力,是工作中学不来的,看看这篇超过90%同行
- [one day learning awk] conditions and cycles
- Create employee data in SAP s/4hana by importing CSV
- [STM32 learning] w25qxx automatic judgment capacity detection based on STM32 USB storage device
- 2022-07-01日报:谷歌新研究:Minerva,用语言模型解决定量推理问题
- Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
- Day 3 of rhcsa study
- Redis秒杀demo
- Crypto Daily:孙宇晨在MC12上倡议用数字化技术解决全球问题
猜你喜欢

工厂高精度定位管理系统,数字化安全生产管理

Nuxt.js数据预取

张驰课堂:六西格玛数据的几种类型与区别

ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification

【php毕业设计】基于php+mysql+apache的教材管理系统设计与实现(毕业论文+程序源码)——教材管理系统

硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件
![[open source data] open source data set for cross modal (MRI, Meg, eye movement) human spatial memory research based on virtual reality scenes](/img/73/98e4847783be26d86d147425ce3ecd.jpg)
[open source data] open source data set for cross modal (MRI, Meg, eye movement) human spatial memory research based on virtual reality scenes
![[stm32-usb-msc problem help] stm32f411ceu6 (Weact) +w25q64+usb-msc flash uses SPI2 to read out only 520kb](/img/ec/fa51b21468708609f998de1b2b84fe.jpg)
[stm32-usb-msc problem help] stm32f411ceu6 (Weact) +w25q64+usb-msc flash uses SPI2 to read out only 520kb

Detailed explanation of stm32adc analog / digital conversion

Hardware development notes (9): basic process of hardware development, making a USB to RS232 module (8): create asm1117-3.3v package library and associate principle graphic devices
随机推荐
大龄测试/开发程序员该何去何从?是否会被时代抛弃?
process.env.NODE_ENV
2023届春招实习-个人面试过程和面经分享
华为发布HCSP-Solution-5G Security人才认证,助力5G安全人才生态建设
Seate中用了shardingjdbc 就不能用全局事务了吗?
说明 | 华为云云商店「商品推荐榜」
Go语学习笔记 - gorm使用 - 表增删改查 | Web框架Gin(八)
【LeetCode】43. String multiplication
vim 从嫌弃到依赖(22)——自动补全
Trace the source of drugs and tamp the safety dike
The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's eldest disciple
Deep operator overloading (2)
精益六西格玛项目辅导咨询:集中辅导和点对点辅导两种方式
表格存储中tablestore 目前支持mysql哪些函数呢?
药品溯源夯实安全大堤
Programming examples of stm32f1 and stm32subeide - production melody of PWM driven buzzer
MySQL高级篇4
如何写出好代码 - 防御式编程指南
【STM32学习】 基于STM32 USB存储设备的w25qxx自动判断容量检测
Stm32f4-tft-spi timing logic analyzer commissioning record