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

How to delete data in laravel

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-01-13 16:58:17
Original
4699 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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template