I want to get all related articles of particular article based on category.
I have relation between Article and Category
Article.php
public function category(){
return $this->belongsTo(ArticleCategory::class,'category_id','id');
}
ArticleCategory.php
public function articles(){
return $this->hasMany(Article::class,'category_id','id');
}
ArticleController.php
public function singleArticle(Article $article){
// I want to convert this statement to eager loading statement
$relatedArticles = $article->category->articles;
return view('pages/article',compact('article','relatedArticles'));
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rMcTVw
via IFTTT
Aucun commentaire:
Enregistrer un commentaire