Answer the question
In order to leave comments, you need to log in
What type of relationship is needed here?
There are tables:
Users (id, name)
Articles (id, title)
Favorites_list (id, user_id, article_id)
Article_rating_log (id, user_id, article_id, score)
public function favorite_list()
{
return $this->hasMany('App\Models\FavoriteList');
}
public function article()
{
return $this->belongsTo('App\Models\Article');
}
public function user()
{
return $this->belongsTo('App\Models\User');
}
Answer the question
In order to leave comments, you need to log in
Class FavoritesList()
{
public function articleRatingLog()
{
// Нужно указать несколько ключей для корректной связи
// На обратной стороне также
return $this->hasOne('App\ArticleRatingLog', ['user_id', 'article_id'], ['user_id', 'article_id']);
}
}
$user->favoriteList[$index]->articleRatingLog->score;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question