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

How to modify data in laravel

WBOY
Release: 2022-01-13 16:39:13
Original
3169 people have browsed it

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';
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template