Add unlike method

This commit is contained in:
2021-04-08 14:11:38 +02:00
parent bbb33e81db
commit 7c8ef2a013

View File

@@ -36,9 +36,8 @@ export default class PostsController {
} }
public async unlike ({params, response}: HttpContextContract) { public async unlike ({params, response}: HttpContextContract) {
let post = await Post.findBy('slug', params.slug) let post = await Post.findByOrFail('slug', params.slug)
if (post) {
await post.merge({ await post.merge({
likes: post.likes-- likes: post.likes--
}).save() }).save()
@@ -47,6 +46,5 @@ export default class PostsController {
post post
}) })
} }
}
} }