Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Traits/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ trait Id
{
private function getId(): int|string|null
{
if ($this->resource === null) {
return null;
}

return $this->toId() ?? $this->guessId();
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/JsonApiResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function test_non_eloquent_resource()
$response->assertJsonFragment(['id' => $intern->id]);
}

public function test_null_resource_handled_gracefully()
{
Route::get('test-route', fn () => new InternResource(null));
$response = $this->getJson('test-route');

$response->assertJson(['data' => []]);
}

public function test_basic_resource_collection()
{
$developers = Developer::factory()->count(3)->create();
Expand Down
Loading