save();"."/> save();".">

Home  >  Article  >  PHP Framework  >  How to modify data in laravel

How to modify data in laravel

WBOY
WBOYOriginal
2022-01-13 16:39:133130browse

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();”.

How to modify data in laravel

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:

How to modify data in laravel

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn