*/ class CommentRepository extends BaseRepository implements CommentRepositoryInterface { public function __construct(Comment $model) { parent::__construct($model); } /** * @param array $filters * @return LengthAwarePaginator */ public function paginate(array $filters = [], int $perPage = 15): LengthAwarePaginator { $query = $this->model->newQuery(); if (isset($filters['is_approved'])) { $query->where('is_approved', filter_var($filters['is_approved'], FILTER_VALIDATE_BOOLEAN)); } if (! empty($filters['commentable_type'])) { $query->where('commentable_type', $filters['commentable_type']); } if (! empty($filters['search'])) { $query->where(function ($q) use ($filters) { $q->where('author_name', 'like', '%'.$filters['search'].'%') ->orWhere('content', 'like', '%'.$filters['search'].'%'); }); } return $query->latest()->paginate($perPage); } /** * @return Collection */ public function getApprovedByCommentable(string $commentableType, int $commentableId): Collection { return $this->model->newQuery() ->where('commentable_type', $commentableType) ->where('commentable_id', $commentableId) ->where('is_approved', true) ->latest() ->get(); } }