Post Count in AdonisJs

I have this in my HomeController

'use strict'

const Post = use('App/Models/Post')

class HomeController {
    async home ({ view }){
        //Fetch a post
        const posts = await Post.query().orderBy('id','desc').fetch()
        return view.render('home', { posts: posts.toJSON() })
    }
}

module.exports = HomeController

How can i get the count of all the numbers of post in my database and display it in my view?

https://adonisjs.com/docs/4.1/query-builder#_count

2 Likes