實務上有可能會遇到資料若存在就更新,不存在就塞進去,Laravel提供了好用的方法 updateOrInsert: 表示用A, B, C三個欄位當作條件,如果值存在就更新D欄位的資料,如果不存在就insert一筆新的。 與updateOrCreate差別是,updateOrCreate會自動維護created_at, updated_at欄位。 本筆記參考:1. https://www.bestinterviewquestion.com/question/how-to-use-updateorinsert-method-in-laravel-query-asogm3909ae2. https://blog.csdn.net/u010324331/article/details/82698211