Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Resource Links

Laravel Resource Links Laravel Package

spatie/laravel-resource-links

Abandoned package that adds action URLs to Laravel API resources. Generate per-item and collection links (show/edit/update/delete, index/create/store) from a controller or defined actions, so resources include ready-to-use endpoints without manual URL building.

View on GitHub
Deep Wiki
Context7

Add links to Laravel API resources

Frequently asked questions about Laravel Resource Links
How do I add action links (e.g., show, edit, delete) to a Laravel JsonResource without manually writing route() calls?
Use the `HasLinks` trait in your resource class and call `$this->links(YourController::class)` in `toArray()`. The package auto-generates URLs for standard actions like `show`, `edit`, `update`, and `delete` based on your controller methods. For example, `links(UsersController::class)` adds all relevant URLs for a user resource.
Does this package support Laravel 9 or 10? The last release was in 2021.
No, the package is abandoned and may not work with Laravel 9/10 due to route macro changes or API updates. Test it in a staging environment first, or fork the package to add compatibility. Consider using a newer alternative like `spatie/laravel-hateoas` if maintenance is critical.
Can I customize the links generated for a resource, like adding a 'profile' link for a user?
The package only generates links for standard controller actions (e.g., `index`, `show`, `edit`). To add custom links, you’ll need to manually include them in `toArray()` alongside the auto-generated links. There’s no built-in support for dynamic or non-standard routes.
How do I add collection-level links (e.g., 'index' or 'create') to API responses?
Use the `HasMeta` trait and define a static `meta()` method in your resource. Call `self::collectionLinks(YourController::class)` to include links like `index`, `create`, or `store` in the response’s `meta` field. This keeps collection-level URLs separate from individual resource links.
Will this package work with nested resources (e.g., a UserResource with a posts relationship)?
The package doesn’t natively support nested resources or polymorphic routes. You’ll need to manually handle links for relationships or override the `links()` method. Test thoroughly, as the package assumes flat resource structures tied to a single controller.
Is there a fallback if the package breaks in production? What if a link is missing?
Since the package is abandoned, there’s no official support. Plan for manual URL generation as a fallback by using Laravel’s `route()` helper or hardcoding URLs. You can also gracefully handle missing links by checking if `$this->links()` returns valid data before including it in `toArray()`.
Does this package work with API versioning (e.g., /v1/users) or custom route namespaces?
The package should work with versioned routes as long as your controller methods and routes are properly defined. However, untested edge cases (like deeply nested versioning) may require manual overrides. Always validate the generated URLs match your expected API structure.
How do I install and configure this package in a Laravel project?
Run `composer require spatie/laravel-resource-links`, then add the `HasLinks` and `HasMeta` traits to your resource class. No additional configuration is needed unless you publish the package’s config (though it’s minimal). Ensure your Laravel version is 5.8+ and test thoroughly.
Are there alternatives to this package for adding HATEOAS links to Laravel APIs?
Yes, consider `spatie/laravel-hateoas` (more actively maintained) or `darkaonline/l5-swagger` for Swagger/OpenAPI integration. For GraphQL APIs, use built-in tools like Laravel GraphQL’s directives. If you need lightweight HATEOAS, this package works, but its abandonment makes alternatives safer for long-term projects.
Can I use this package with third-party API tools like Postman or Swagger?
Yes, the generated links are embedded in your JSON responses, so tools like Postman or Swagger can parse them. However, there’s no built-in documentation or OpenAPI schema generation. You’ll need to manually document the `links` and `meta` fields in your API specs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport