<?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的模型中,加入这个
就是删除订单后,继续删除订单商品
标签:laravel,use,删除,订单,模型,id,public,order From: https://blog.51cto.com/jing/6002552