Make a Larvel Model insertion or update note, because there are many mistakes Author: Chuwen Time: 2021-09-03 Classification: Laravel , PHP ###Create new data or update data for Larravel model >Maybe my method is not elegant enough. You are welcome to criticize me ```php <? php namespace App\Models; Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Content extends Model { use HasFactory; protected $dateFormat = 'U';// U: Timestamp //Create new data or update data public static function insertOrUpdate(int $id, int $uid) { //Find data first $content = Content::whereId($id)->first(); //If empty if (is_null($content)) { //Create model instance $content = new Content; $content->uid = $uid; } $content ->text='Test'; //Create new data or update data $content->save(); } } ``` Leave a link to the Chinese document: https://learnku.com/docs/laravel/8.x/eloquent/9406#c7d398 label: Laravel , Model