💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
>[danger] 批量彻底删除 ~~~ $data = User::onlyTrashed()->select($ids); foreach ($data as $v) { $v->force()->delete(); } ~~~ >[danger] 批量恢复数据 ~~~ $data = User::onlyTrashed()->select($ids); foreach ($data as $v) { $v->restore(); } ~~~ >[danger] 模型关联软删除 ``` public function user() { return $this->belongsTo(User::class, 'user_id', 'id')->removeOption('soft_delete'); } ``` >[danger] 常用方法 ``` useSoftDelete('delete_time', time()) ``` >[danger] 关联删除优雅写法 ``` /** * 删除商家 * * @param integer $merch_id 商家id */ public static function delete(int $merch_id) { $merch = ModelMerch::with(['goods'])->findOrEmpty($merch_id); $merch->isEmpty() && fault('商家不存在或已被删除'); // 启动事务 $merch->startTrans(); try { // 删除活动及其中奖者信息 $raffle = $merch->raffle()->with(['winning'])->select(); foreach ($raffle as $v) { $v->together(['winning'])->delete(); } // 删除商家及其商品 $merch->together(['goods'])->delete(); $merch->commit(); } catch (\Exception $e) { $merch->rollback(); fault('删除失败'); } } ```