Laravel eloquent update record without loading from database

后端 未结 5 1049
无人共我
无人共我 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 00:24

    You can simply use Query Builder rather than Eloquent, this code directly update your data in the database :) This is a sample:

    DB::table('post')
                ->where('id', 3)
                ->update(['title' => "Updated Title"]);
    

    You can check the documentation here for more information: http://laravel.com/docs/5.0/queries#updates

提交回复
热议问题