Skip to content

Commit

Permalink
Merge pull request #11 from swisnl/feature/throw-meaningful-exception…
Browse files Browse the repository at this point in the history
…-when-no-resources-are-found

Throw meaningful exception when no resources are found
  • Loading branch information
JaZo authored Mar 29, 2023
2 parents 5d524ce + b2e6922 commit ea54080
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/ResourceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public function resource($model): JsonApiResource
$this->loadResources($fqn);
}

return $this->resources[$fqn]->first();
$resource = $this->resources[$fqn]->first();

if (!$resource) {
throw new \RuntimeException(sprintf('No resource found for model [%s], make sure your database is seeded!', $fqn));
}

return $resource;
}

/**
Expand All @@ -45,7 +51,13 @@ public function resources($model): array
$this->loadResources($fqn);
}

return $this->resources[$fqn]->toArray();
$resources = $this->resources[$fqn]->toArray();

if (empty($resources)) {
throw new \RuntimeException(sprintf('No resources found for model [%s], make sure your database is seeded!', $fqn));
}

return $resources;
}

protected function getFQN($model): string
Expand Down

0 comments on commit ea54080

Please sign in to comment.