在模型中增加
protected static function booted()
{
static::deleting(function ($_it) {
$total = 1; //在這里去做邏輯判斷,$_it->id 可以拿到當前操作id
if ($total > 0) {
throw new \Exception("無法刪除");
}
return true;
});
}
后來我才知道這個是laravel框架的模型生命周期事件。。。
再后來利用這些個模型事件實現了很多功能- -,,,持續學習中