当前位置:网站首页>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的模型中,加入这个
就是删除订单后,继续删除订单商品
边栏推荐
- What time do you get off work?!!!
- Introduction to RT thread env tool (learning notes)
- ATSs: automatically select samples to eliminate the difference between anchor based and anchor free object detection methods
- u本位合约和币本位合约有区别,u本位合约会爆仓吗
- [target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
- VIM from dislike to dependence (22) -- automatic completion
- Summary of point cloud reconstruction methods I (pcl-cgal)
- [video memory optimization] deep learning video memory optimization method
- ABAP-调用Restful API
- 工厂高精度定位管理系统,数字化安全生产管理
猜你喜欢

What is the forkjoin framework in the concurrent programming series?
![[one day learning awk] function and user-defined function](/img/e1/a378211ef05fcc4d469363f3e509a7.png)
[one day learning awk] function and user-defined function

精益六西格玛项目辅导咨询:集中辅导和点对点辅导两种方式

最新NLP赛事实践总结!

电脑照片尺寸如何调整成自己想要的

"Qt+pcl Chapter 6" point cloud registration ICP Series 6
![[IDM] IDM downloader installation](/img/2b/baf8852b422c1c4a18e9c60de864e5.png)
[IDM] IDM downloader installation

Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results

The latest NLP game practice summary!

马来西亚《星报》:在WTO MC12 孙宇晨仍在坚持数字经济梦想
随机推荐
《性能之巅第2版》阅读笔记(五)--file-system监测
Don't ask me again why MySQL hasn't left the index? For these reasons, I'll tell you all
Task. Run(), Task. Factory. Analysis of behavior inconsistency between startnew() and new task()
Équipe tensflow: Nous ne sommes pas abandonnés
Redis high availability principle
并发编程系列之什么是ForkJoin框架?
Is JPMorgan futures safe to open an account? What is the account opening method of JPMorgan futures company?
MySQL backup and restore single database and single table
【开源数据】基于虚拟现实场景的跨模态(磁共振、脑磁图、眼动)人类空间记忆研究开源数据集
Win11如何设置用户权限?Win11设置用户权限的方法
[target tracking] | template update time context information (updatenet) "learning the model update for Siamese trackers"
[cloud trend] new wind direction in June! Cloud store hot list announced
Qt+pcl Chapter 6 point cloud registration ICP series 3
张驰课堂:六西格玛数据的几种类型与区别
她就是那个「别人家的HR」|ONES 人物
Qt+pcl Chapter 9 point cloud reconstruction Series 2
表格存储中tablestore 目前支持mysql哪些函数呢?
马来西亚《星报》:在WTO MC12 孙宇晨仍在坚持数字经济梦想
TensorFlow团队:我们没被抛弃
软件测试的可持续发展,必须要学会敲代码?