Method: 1. Use the find method to obtain the corresponding record and return an object. The syntax is "UserModel::find($id)"; 2. Use the save method to set the data to be updated for the object. That’s it, the syntax is “$user->save();”.
The operating environment of this tutorial: Windows 10 system, Laravel version 5.5, DELL G3 computer.
How to modify data in laravel
#If you need to update data in laravel, you need to first call the find method of the model to obtain the corresponding record and return a Object, then set the data to be updated for the object, and finally call the save method.
For example:
$user = UserModel::find($id); $user->title = $_POST['title']; $user->content= $_POST['content']; return $user->save() ? 'OK' : 'fail';
The example is as follows:
Related recommendations:The latest five Laravel video tutorials
The above is the detailed content of How to modify data in laravel. For more information, please follow other related articles on the PHP Chinese website!