Skip to content

Commit 59e3157

Browse files
authored
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.
1 parent 8012da9 commit 59e3157

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Includes/IncludedCount.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class IncludedCount implements IncludeInterface
99
{
1010
public function __invoke(Builder $query, string $count)
1111
{
12-
$query->withCount(Str::before($count, config('query-builder.count_suffix', 'Count')));
12+
$suffix = config('query-builder.count_suffix', 'Count');
13+
$relation = Str::endsWith($count, $suffix) ? Str::beforeLast($count, $suffix) : $count;
14+
15+
$query->withCount($relation);
1316
}
1417
}

0 commit comments

Comments
 (0)