Skip to content

Commit 87ee130

Browse files
committed
Pagination
1 parent 0325ec8 commit 87ee130

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Models/Rating.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ public function updateRating($id, $data)
8383
*
8484
* @return mixed
8585
*/
86-
public function getAllRatings($id, $sort = 'desc')
86+
public function getAllRatings($id, $paginate, $perPage, $sort = 'desc')
8787
{
88-
$rating = $this->select('*')
88+
if($paginate){
89+
$rating = $this->select('*')
90+
->where('reviewrateable_id', $id)
91+
->orderBy('created_at', $sort)
92+
->paginate($perPage);
93+
}else{
94+
$rating = $this->select('*')
8995
->where('reviewrateable_id', $id)
9096
->orderBy('created_at', $sort)
9197
->get();
92-
98+
}
9399
return $rating;
94100
}
95101

src/Traits/ReviewRateable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function countPriceRating($onlyApproved = false)
228228
$where = $onlyApproved ? [['approved', '1']] : [];
229229

230230
return $this->ratings()
231-
->selectRaw('count(price_rating) as countPriceReviewRateable')
231+
->selectRaw('count(pricing_rating) as countPriceReviewRateable')
232232
->where($where)
233233
->get()
234234
->first()
@@ -296,9 +296,9 @@ public function updateRating($id, $data, Model $parent = null)
296296
*
297297
* @return mixed
298298
*/
299-
public function getAllRatings($id, $sort = 'desc')
299+
public function getAllRatings($id, $paginate = false, $perPage = 5, $sort = 'desc')
300300
{
301-
return (new Rating())->getAllRatings($id, $sort);
301+
return (new Rating())->getAllRatings($id, $paginate, $perPage, $sort);
302302
}
303303

304304
/**

0 commit comments

Comments
 (0)