delete()"."/> delete()".">

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

How to delete data in laravel

WBOY
WBOYOriginal
2022-01-13 16:58:174610browse

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';

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!

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