testy
654
11
General

Laravel 5 problems with relations pivot

Posted 4 years ago by testy

I 'm just not on the solution :(

I have 3 Tables

- users (id, username, ...)
- entrys (id, title, ..)
- favourites (id, user_id, entry_id)

I need that favourites table is a pivot table from users and entrys.

My Models

class User extends Model {

  public function entrys() {
     return $this->hasMany('App\Entrys');
   }

    public function favourites() {
      return $this->hasMany('App\Favourite');
    }
}

class Entrys extends Moldel {

  public function favourite() {
    return $this->hasMany('App\Favourite');
  }

  public function user()
  {
    return $this->belongsToMany('App\User');
  }
}

class Favourite extends Model {

   public function entrys() {
      return $this->belongsTo('App\Entry');
    }

    public function user() {
      return $this->belongsTo('App\User');
    }
}

Please sign in or create an account to participate in this conversation.