Skip to content

Commit 831b846

Browse files
committed
Allow models into related.
1 parent ac51e0f commit 831b846

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Repositories/Repository.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Binaryk\LaravelRestify\Traits\InteractWithSearch;
1616
use Binaryk\LaravelRestify\Traits\PerformsQueries;
1717
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
18+
use Illuminate\Database\Eloquent\Builder;
1819
use Illuminate\Database\Eloquent\Model;
20+
use Illuminate\Database\Eloquent\Relations\Relation;
1921
use Illuminate\Http\Request;
2022
use Illuminate\Http\Resources\ConditionallyLoadsAttributes;
2123
use Illuminate\Http\Resources\DelegatesToResource;
@@ -520,15 +522,22 @@ public function resolveRelationships($request): array
520522
$paginator = $this->resource->{$relation}();
521523

522524
if ($paginator instanceof Model) {
525+
$withs[$relation] = $paginator;
523526
continue;
524527
}
525528

526529
if ($paginator instanceof Collection) {
530+
$withs[$relation] = $paginator;
527531
continue;
528532
}
529533

530-
/** * @var AbstractPaginator $paginator */
531-
$paginator = $paginator->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get();
534+
if (
535+
$paginator instanceof Relation ||
536+
$paginator instanceof Builder
537+
) {
538+
/** * @var AbstractPaginator $paginator */
539+
$paginator = $paginator->take($request->input('relatablePerPage') ?? (static::$defaultRelatablePerPage ?? RestifySearchable::DEFAULT_RELATABLE_PER_PAGE))->get();
540+
}
532541
}
533542

534543
$withs[$relation] = $paginator instanceof Collection

0 commit comments

Comments
 (0)