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 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

Product Decisions This Supports

  • API Consistency & Developer Experience (DX):

    • Standardize API response structures by embedding HATEOAS (Hypermedia as the Engine of Application State) links in Laravel API resources, reducing manual URL construction and improving DX for frontend teams.
    • Align with modern API design principles (e.g., GraphQL-like self-descriptive endpoints) to accelerate frontend development and reduce API documentation overhead.
  • Roadmap: API-First Strategy

    • Justify investment in API-first development by reducing backend/frontend friction. This package enables "discoverable" APIs, where clients (mobile, web, third-party) can dynamically explore endpoints without static docs.
    • Prioritize for projects where API consumers (e.g., mobile apps, SPAs) rely on backend-provided metadata for navigation or dynamic feature toggling.
  • Build vs. Buy: Low-Effort HATEOAS

    • Buy: Avoid reinventing HATEOAS link generation for CRUD APIs. The package eliminates boilerplate (e.g., manually adding links: { self: "/users/1", edit: "/users/1/edit" } to every resource).
    • Build: Only consider custom solutions if requirements exceed HATEOAS (e.g., complex nested relationships or non-standard actions). Otherwise, this package reduces technical debt.
  • Use Cases:

    • Admin Panels/Dashboards: Dynamically generate action buttons (e.g., "Edit," "Delete") with pre-built URLs.
    • Mobile Apps: Reduce hardcoded API paths by embedding links in responses (e.g., user.links.edit for deep-linking).
    • Internal Tools: Accelerate development of internal tools that consume the same API as public endpoints.
    • Legacy API Modernization: Retrofit HATEOAS to existing APIs with minimal code changes.

When to Consider This Package

  • Adopt When:

    • Your team prioritizes API discoverability and wants to reduce frontend/backend handoff friction.
    • You’re building a CRUD-heavy API (e.g., SaaS platforms, CMS backends) where standard actions (index, show, edit) are repetitive.
    • Frontend teams (e.g., React, Vue) lack direct access to backend routes or rely on API docs for URL construction.
    • You’re using Laravel’s JsonResource and want to avoid manual link generation in every resource class.
    • The project has low-to-medium complexity in API relationships (not ideal for highly nested or polymorphic resources).
  • Look Elsewhere If:

    • Archived Status: The package is abandoned (last release 2021). Evaluate risks of long-term maintenance (e.g., Laravel version compatibility).
    • Complex Relationships: Need advanced HATEOAS features (e.g., dynamic link generation based on user roles, nested resource links, or GraphQL-like query parameters). Consider alternatives like:
    • Performance Constraints: Adding links to every resource may increase payload size. Profile impact if responses are large (e.g., media-heavy APIs).
    • Non-Laravel Stack: Not applicable outside PHP/Laravel ecosystems.
    • GraphQL Adoption: If migrating to GraphQL, prioritize GraphQL tools (e.g., Laravel GraphQL) over REST HATEOAS.

How to Pitch It (Stakeholders)

For Executives:

"This package lets our API ‘speak for itself’—reducing dev time and errors.

  • Problem: Frontend teams spend time reverse-engineering API routes from docs or hardcoding URLs, leading to bugs and slow iterations.
  • Solution: Automatically embed actionable links (e.g., edit, delete) in every API response, so clients (mobile apps, dashboards) can navigate dynamically—like a self-driving API.
  • Impact:
    • Faster Development: Frontend teams get URLs without asking backend for docs.
    • Lower Risk: Eliminates broken links from manual URL construction.
    • Future-Proof: Aligns with API-first strategies for third-party integrations or internal tools.
  • Tradeoff: Minimal upfront cost (MIT-licensed, open-source) with long-term DX gains. Note: Package is unmaintained, but the pattern is battle-tested—we’d need to fork or replace if issues arise."

For Engineering Leaders:

"Cut API boilerplate and standardize HATEOAS with minimal effort.

  • Why It Matters:
    • DRY Principle: Replace repetitive links: { self: "/users/1" } code in every JsonResource with a single use Spatie\ResourceLinks\HasLinks.
    • Consistency: Enforce uniform API responses across teams (e.g., all show endpoints include edit/delete links by default).
    • Tooling Synergy: Works seamlessly with Laravel’s existing ecosystem (e.g., API resources, controllers).
  • Implementation:
    • Add the package to composer.json and enable links in resources:
      class UserResource extends JsonResource {
          use \Spatie\ResourceLinks\HasLinks;
          // ...
      }
      
    • Links auto-generate from route names (e.g., users.edit/users/{id}/edit).
  • Risks/Mitigations:
    • Abandoned Package: Fork or monitor for critical issues. Alternatives: Custom trait or spatie/laravel-activitylog for inspiration.
    • Overhead: Links add ~50–100 bytes per response. Profile in staging before production.
  • Next Steps:
    1. Pilot with 1–2 high-traffic resources (e.g., User, Order).
    2. Measure frontend dev time saved (e.g., fewer API doc requests).
    3. Extend for custom actions (e.g., links(['publish' => route('posts.publish', $this)]))."

For Developers:

"Never write route('users.edit', $user) in a resource again.

  • How It Works:
    • Add use HasLinks to your JsonResource—links appear automatically in the links array.
    • Example output:
      {
        "id": 1,
        "name": "John",
        "links": {
          "self": "/users/1",
          "edit": "/users/1/edit",
          "delete": "/users/1"
        }
      }
      
  • Customization:
    • Exclude actions: links(['except' => ['delete']]).
    • Add custom links: links(['publish' => route('posts.publish', $this)]).
  • Gotchas:
    • Archived: No new features, but core functionality is stable.
    • Route Names: Links rely on Laravel’s route naming (e.g., users.edit). Misnamed routes = broken links.
  • Win: Spend 10 mins setup, save hours of manual link management."
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