Skip to content

Commit e355de9

Browse files
committed
[Refactor] Adjust implementation for allowing zero as a resource id
1 parent 1ed618b commit e355de9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## Unreleased
7+
8+
### Fixed
9+
10+
- [#178](https://github.com/laravel-json-api/laravel/issues/178) Allow a resource id that is `"0"`.
11+
612
## [2.1.0] - 2022-02-20
713

814
### Added

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
"require": {
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
28-
"laravel-json-api/core": "^2.1",
28+
"laravel-json-api/core": "^2.2",
2929
"laravel-json-api/eloquent": "^2.1",
3030
"laravel-json-api/encoder-neomerx": "^2.0",
3131
"laravel-json-api/exceptions": "^1.1",
32-
"laravel-json-api/spec": "^1.1",
32+
"laravel-json-api/spec": "^1.1.1",
3333
"laravel-json-api/validation": "^2.0",
3434
"laravel/framework": "^8.76|^9.0"
3535
},

src/Routing/Route.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use LaravelJsonApi\Contracts\Schema\Relation;
2828
use LaravelJsonApi\Contracts\Schema\Schema;
2929
use LaravelJsonApi\Contracts\Server\Server;
30+
use LaravelJsonApi\Core\Document\ResourceIdentifier;
3031
use LogicException;
3132
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3233

@@ -101,11 +102,11 @@ public function modelOrResourceId()
101102

102103
$modelOrResourceId = $this->route->parameter($name);
103104

104-
if (!empty($modelOrResourceId) || '0' === $modelOrResourceId) {
105-
return $modelOrResourceId;
105+
if (!is_object($modelOrResourceId) && ResourceIdentifier::idIsEmpty($modelOrResourceId)) {
106+
throw new LogicException('No JSON API resource id set on route.');
106107
}
107108

108-
throw new LogicException('No JSON API resource id set on route.');
109+
return $modelOrResourceId;
109110
}
110111

111112
/**

0 commit comments

Comments
 (0)