November 2018
Beginner
132 pages
2h 57m
English
Finally, we will create controller methods for the various actions we want our application to be able to carry out. These include the following:
Let's create a controller file for our post actions name PostController in the controllers folder, and insert the following contents into it:
// ./controllers/PostController.jsconst Post = require('../models/Post');module.exports = { async index(ctx) { const posts = await Post.find() .populate('author'); ctx.state.posts = posts; ctx.state.title ...Read now
Unlock full access