From 59e3157caed9229e3259fb8f3e366800d4040a6b Mon Sep 17 00:00:00 2001 From: Arushad Ahmed Date: Sat, 19 Oct 2024 13:31:42 +0500 Subject: [PATCH] Fixed IncludedCount.php Fixed bug where the include count fails if a relation has the word `Count` in it. For example, it fails for `billingCountry` by removing the word `Country` and trying to load a `billing` relation. --- src/Includes/IncludedCount.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Includes/IncludedCount.php b/src/Includes/IncludedCount.php index 4e2c05d6..67f3eb1a 100644 --- a/src/Includes/IncludedCount.php +++ b/src/Includes/IncludedCount.php @@ -9,6 +9,9 @@ class IncludedCount implements IncludeInterface { public function __invoke(Builder $query, string $count) { - $query->withCount(Str::before($count, config('query-builder.count_suffix', 'Count'))); + $suffix = config('query-builder.count_suffix', 'Count'); + $relation = Str::endsWith($count, $suffix) ? Str::beforeLast($count, $suffix) : $count; + + $query->withCount($relation); } }