Table of Contents

    lso, let's define the relationship between User and Favorites. A user can like multiple tweets, while a single favorite is by a particular user. This is a one-to-many relationship. Open app/Models/User.js and add the code below to it:

    // app/Models/User.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
    user () {
        return this.belongsTo('App/Models/User')

    Chimezie Enyinnaya

    20 posts

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