Laravel 8 恢復軟刪除模型

2021-07-19 11:32 更新

有時會對軟刪除模型進行「撤銷」,在已軟刪除的數據上使用 restore 方法即可恢復到有效狀態(tài):

$flight->restore(); 

你也可以在查詢中使用 restore 方法,從而快速恢復多個模型。和其他「批量」操作一樣,這個操作不會觸發(fā)模型的任何事件:

App\Models\Flight::withTrashed()
        ->where('airline_id', 1)
        ->restore(); 

類似 withTrashed 方法,restore 方法也用在 關聯(lián)上:

$flight->history()->restore(); 


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號