To delete a record from the database using Eloquent in Laravel, you can use the delete()
method. Here are the steps:
find()
, where()
, etc. For example:$record = ModelName::find($id);
delete()
method on it. For example:$record->delete();
Alternatively, you can directly chain the delete()
method after querying the record. For example:
ModelName::where('column', 'value')->delete();
Note: The delete()
method will remove the record from the database permanently. If you want to soft delete the record (i.e., mark it as deleted without actually removing it from the database), you can use the delete()
method on a model that uses the SoftDeletes
trait.