A

Table of Contents

    tweet can have multiple favorites, while a single favorite is for a particular tweet. This is a one-to-many relationship. Open app/Models/Tweet.js and add the code below to it:

    // app/Models/Tweet.js
    
    favorites() {
        return this.hasMany('App/Models/Favorite')
    }

    Then define the inverse relationship on the Favorite model. Open app/Models/Favorite.js and add the code below to it:

    // app/Models/Favorite.js
    
    tweet () {
        return this.belongsTo('App/Models/Tweet')
    }

    Chimezie Enyinnaya

    19 posts

    Software Developer [PHP Laravel JavaScript NodeJS AdonisJS VueJS] | movie lover | run http://openlaravel.com