From a353f906c3998a842854da777c8e86be7fc11050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Wed, 17 Aug 2022 08:42:38 +0200 Subject: [PATCH] Urls --- src/Extracts/Extract.php | 1 + src/Fields/Media.php | 1 + src/Http/Controllers/NotificationsController.php | 2 ++ src/Http/Controllers/RelationController.php | 1 + src/Resources/Resource.php | 1 + src/Root.php | 2 +- src/Traits/AsSubResource.php | 1 + tests/Http/Controllers/NotificationsControllerTest.php | 2 +- tests/Http/Controllers/RelationControllerTest.php | 1 + 9 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Extracts/Extract.php b/src/Extracts/Extract.php index e92515c1..ae5e37c0 100644 --- a/src/Extracts/Extract.php +++ b/src/Extracts/Extract.php @@ -194,6 +194,7 @@ public function mapItems(ExtractRequest $request): array ->latest() ->paginate($request->input('per_page')) ->withQueryString() + ->setPath($this->getUri()) ->through(function (Model $model) use ($request): array { return (new ModelResource($model))->toDisplay( $request, $this->resolveFields($request)->available($request, $model) diff --git a/src/Fields/Media.php b/src/Fields/Media.php index 03ef8a38..7d50e5e0 100644 --- a/src/Fields/Media.php +++ b/src/Fields/Media.php @@ -234,6 +234,7 @@ public function mapItems(ResourceRequest $request, Model $model): array ->latest() ->paginate($request->input('per_page')) ->withQueryString() + ->setPath($this->getUri()) ->through(function (Model $related) use ($request, $model): array { return $this->mapOption($request, $model, $related); }) diff --git a/src/Http/Controllers/NotificationsController.php b/src/Http/Controllers/NotificationsController.php index a1f368bc..f2a9f9fa 100644 --- a/src/Http/Controllers/NotificationsController.php +++ b/src/Http/Controllers/NotificationsController.php @@ -4,6 +4,7 @@ use Cone\Root\Http\Requests\RootRequest; use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\URL; class NotificationsController extends Controller { @@ -20,6 +21,7 @@ public function index(RootRequest $request): JsonResponse ->filter($request) ->latest() ->paginate($request->input('per_page')) + ->setPath(URL::route('root.api.notifications.index', [], false)) ->withQueryString(); return new JsonResponse(array_merge($notifications->toArray(), [ diff --git a/src/Http/Controllers/RelationController.php b/src/Http/Controllers/RelationController.php index 9ded3c01..09a42bb5 100644 --- a/src/Http/Controllers/RelationController.php +++ b/src/Http/Controllers/RelationController.php @@ -29,6 +29,7 @@ public function __invoke(ResourceRequest $request): JsonResponse } }) ->paginate() + ->setPath($field->getUri()) ->through(static function (Model $related) use ($request, $model, $field): array { return $field->mapOption($request, $model, $related); }); diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index 1d765778..e6ef7ed4 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -326,6 +326,7 @@ public function mapItems(ResourceRequest $request): array ->latest() ->paginate($request->input('per_page')) ->withQueryString() + ->setPath($this->getUri()) ->through(function (Model $model) use ($request): array { return $this->mapItem($request, $model)->toDisplay( $request, $this->resolveFields($request)->available($request, $model) diff --git a/src/Root.php b/src/Root.php index c219627a..4a0eb365 100644 --- a/src/Root.php +++ b/src/Root.php @@ -15,7 +15,7 @@ abstract class Root * * @var string */ - public const VERSION = '0.8.2'; + public const VERSION = '0.8.3'; /** * The registered callbacks. diff --git a/src/Traits/AsSubResource.php b/src/Traits/AsSubResource.php index bd1858c4..c49bed6e 100644 --- a/src/Traits/AsSubResource.php +++ b/src/Traits/AsSubResource.php @@ -61,6 +61,7 @@ public function mapItems(ResourceRequest $request, Model $model): array $items = $relation->paginate($request->input('per_page')) ->withQueryString() + ->setPath($this->getUri()) ->through(function (Model $related) use ($request, $model): array { return $this->mapItem($request, $model, $related)->toDisplay( $request, $this->resolveFields($request)->available($request, $model, $related) diff --git a/tests/Http/Controllers/NotificationsControllerTest.php b/tests/Http/Controllers/NotificationsControllerTest.php index 7c8915db..00549754 100644 --- a/tests/Http/Controllers/NotificationsControllerTest.php +++ b/tests/Http/Controllers/NotificationsControllerTest.php @@ -22,7 +22,7 @@ public function a_notifications_controller_has_index() $this->actingAs($this->admin) ->get('/root/api/notifications') ->assertOk() - ->assertJson($this->admin->notifications()->paginate()->toArray()); + ->assertJson($this->admin->notifications()->paginate()->setPath('/root/api/notifications')->toArray()); } /** @test */ diff --git a/tests/Http/Controllers/RelationControllerTest.php b/tests/Http/Controllers/RelationControllerTest.php index f916882a..8a003516 100644 --- a/tests/Http/Controllers/RelationControllerTest.php +++ b/tests/Http/Controllers/RelationControllerTest.php @@ -38,6 +38,7 @@ public function a_relation_controller_has_index() $results = $this->field ->resolveQuery($this->request, $model) ->paginate() + ->setPath('/root/posts/fields/author') ->through(function ($related) use ($model): array { return $this->field->mapOption($this->request, $model, $related); });