Build a Twitter Clone With Adonis and Vue

Unfollowing User

Also, let's add ability for users to unfollow one another. Add the code below to start/routes.js within the users group routes we defined in the previous lesson:

// start/routes.js

// unfollow user
Route.delete('/unfollow/:id', 'UserController.unFollow')

This also takes the ID of the user we want to unfollow as a parameter.

Next, add the code below to UserController:

// app/Controllers/Http/UserController.js

async unFollow ({ params, auth, response }) {
    // get currently authenticated user
    const user = auth.current.user

    // remove from user's followers
    await user.following().detach(

    return response.json({
        status: 'success',
        data: null

The is simply an inverse of the follow method as it makes use of the detach method to remove the user with the specified ID from the list of followers of the authenticated user.

Like this article? Follow @ammezie on Twitter