November 2018
Intermediate to advanced
404 pages
10h 16m
English
The delete method is similar to the update method by matching with an existing entry. Once found, you'll call delete(on:) to remove it the item from the database:
func removeEntry(_ req: Request) throws -> Future<Response> { let id = try req.parameters.next(Int.self) return JournalEntry.find(id, on: req).flatMap { entry in guard let entry = entry else { throw Abort(.notFound) } return entry.delete(on: req).transform(to: req.redirect(to: self.mainPage)) }}
After an entry is successfully deleted, the user will be redirected to the application's main screen.
Read now
Unlock full access