Skip to content

Commit

Permalink
feat: throw meaningful exception when no resources are found
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 29, 2023
1 parent 5d524ce commit b2e6922
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 b2e6922

Please sign in to comment.