Creating and Update Laravel Eloquent

后端 未结 13 1456
广开言路
广开言路 2020-11-27 11:59

What\'s the shorthand for inserting a new record or updating if it exists?



        
13条回答
  •  眼角桃花
    2020-11-27 12:42

    One more option if your id isn't autoincrement and you know which one to insert/update:

    $object = MyModel::findOrNew($id);
    //assign attributes to update...
    $object->save();
    

提交回复
热议问题