Skip to content

Commit

Permalink
Fix postdata from response
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Oct 16, 2023
1 parent 8e95400 commit 95a06c8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ContentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function getPosts(string $product, int $page = 1, int $perPage = 2
}

$posts = new Paginator(
items: collect($response['data'])->map(function (array $post) {
items: collect($response['data'])->filter()->map(function (array $post) {
return Post::fromResponse($post);
}),
perPage: $perPage,
Expand All @@ -60,7 +60,11 @@ public static function getPost(string $product, string $slug): ?Post
return Cache::get("post-{$product}-{$slug}");
}

$post = Post::fromResponse($response->json('data.0'));
if (! $postData = $response->json('data.0')) {
return null;
}

$post = Post::fromResponse($postData);

Cache::put("post-{$product}-{$slug}", $post);

Expand Down

0 comments on commit 95a06c8

Please sign in to comment.