Home > PHP Framework > Laravel > body text

How to delete data in laravel

WBOY
Release: 2022-01-13 16:58:17
Original
4618 people have browsed it

How to delete data in laravel: 1. Query the corresponding record according to the primary key id and return an object. The syntax is "UserModel::find($id);"; 2. Call the object to delete the specified one using the delete method. Data is sufficient, and the syntax is "$user->delete()".

How to delete data in laravel

#The operating environment of this article: Windows 10 system, Laravel version 6, Dell G3 computer.

How to delete data in laravel

#If you want to delete data in laravel, you must first query the corresponding record based on the primary key id and return an object. Then call the object's delete method.

For example:

$user = UserModel::find($id);
return $user->delete() ? 'ok' : 'fail';
Copy after login

The example is as follows:

How to delete data in laravel

Related recommendations:The latest five Laravel video tutorials

The above is the detailed content of How to delete 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!