Build a Twitter Clone With Adonis and Vue

Favorite Model and Migration

Users will have the ability to like and dislike tweets. Let's create the Favorite model and its migration file:

adonis make:model Favorite -m

Open database/migrations/TIMESTAMP_favorite_schema.js and update the up method as below:

// database/migrations/TIMESTAMP_favorite_schema.js

up () {
    this.create('favorites', (table) => {
        table.increments()
        table.integer('user_id').unsigned().notNullable()
        table.integer('tweet_id').unsigned().notNullable()
        table.timestamps()
    })
}

This will create a favorites table with the following fields:

  • id
  • user_id
  • tweet_id
  • created_at
  • updated_at

Next, run the migration:

 adonis migration:run