- This is normal code
- TractorTable class
-
UserReviews class Following Code
public function getReviewAvgAndCount() { return $this->hasMany(UserReview::class, 'tractor_id');
}
function getAverageRatingAttribute() { return ($this->getReviewAvgAndCount()->count()); } UserReview:
public function tractorTable() { return $this ->belongsTo('App\Model\TractorTable','tractor_id'); } Call Controller:
TractorTable::with('tractorImage','tractorSpecData','getAverageRatingAttribute','drive')->orderBy('tractor_id', 'desc')->take(5)->get();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire