Laravel eloquent update record without loading from database

后端 未结 5 1048
无人共我
无人共我 2021-02-05 00:06

I\'m quite new to laravel and I\'m trying to update a record from form\'s input. However I see that to update the record, first you need to fetch the record from database. Isn\

5条回答
  •  礼貌的吻别
    2021-02-05 00:35

    Use property exists:

    $post = new Post();
    $post->exists = true;
    $post->id = 3; //already exists in database.
    $post->title = "Updated title";
    $post->save();
    

    Here is the API documentation: http://laravel.com/api/5.0/Illuminate/Database/Eloquent/Model.html

提交回复
热议问题