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 Endpoint Resources Laravel Package

spatie/laravel-endpoint-resources

Abandoned package that adds controller/action-based URL links to Laravel API resources and collection meta. Includes traits to generate “show/edit/update/delete” item links and “index/create/store” collection links automatically.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Aligns with Laravel’s resourceful controllers and API-first design, reducing manual URL construction in JsonResource responses.
    • Follows HATEOAS principles by embedding actionable links (e.g., self, related, collection) in API responses, improving client-side navigation.
    • Lightweight and decoupled from core Laravel, leveraging traits (HasLinks, HasMeta) for modularity.
  • Cons:
    • Abandoned (last release 2021) with no active maintenance or Laravel 10+ compatibility. Risk of breaking changes in newer Laravel versions.
    • Limited to RESTful controllers; non-standard routes (e.g., custom named routes) may require manual overrides.
    • No built-in support for API versioning or dynamic route parameter handling (e.g., nested resources).

Integration Feasibility

  • Low-effort integration for standard CRUD APIs:
    • Add traits to JsonResource classes (e.g., use HasLinks).
    • Define links() method in resource to specify controller actions (e.g., links(UserController::class)).
    • Automatically injects links like self, related, and collection URLs.
  • High-effort edge cases:
    • Custom route namespaces or middleware (e.g., api/v1/users) may need manual route resolution.
    • GraphQL APIs or non-RESTful endpoints are unsupported.
    • Laravel Sanctum/Passport auth: Links may leak unauthorized routes if not filtered (e.g., delete for unauthenticated users).

Technical Risk

  • Critical:
    • No Laravel 10+ support: Potential conflicts with newer Laravel features (e.g., route caching, improved resource classes).
    • Deprecated dependencies: May rely on outdated Spatie packages or Laravel internals.
    • No tests for modern use cases: Risk of hidden bugs in complex routing scenarios.
  • Moderate:
    • Performance overhead: Minimal, but dynamic link generation adds slight runtime cost per request.
    • Route caching conflicts: If using Laravel’s route caching, links may not update until cache refresh.
  • Low:
    • MIT license: No legal barriers to adoption.

Key Questions

  1. Compatibility:
    • Is the package tested against our Laravel version (e.g., 9.x vs. 10.x)?
    • Do we use custom route namespaces (e.g., api/v1) that require manual configuration?
  2. Security:
    • How will we filter links by user permissions (e.g., hide delete for non-admins)?
    • Are there risks of link injection if routes are dynamically generated?
  3. Maintenance:
    • What’s the migration path if this package is deprecated? (e.g., manual link generation or alternatives like spatie/laravel-hal).
    • Are there alternatives (e.g., spatie/laravel-fractal, nWidart/laravel-routes) with active maintenance?
  4. Testing:
    • How will we test link generation in CI? (e.g., mock routes or use Route::getRoutes()).
    • Are there edge cases (e.g., optional route parameters) that break link generation?

Integration Approach

Stack Fit

  • Best for:
    • Laravel API projects using JsonResource for responses.
    • Teams prioritizing HATEOAS and discoverable APIs.
    • Applications with standard RESTful controllers (minimal custom routing).
  • Poor fit:
    • Non-RESTful APIs (e.g., GraphQL, WebSockets).
    • Projects using custom route generation (e.g., dynamic route parameters).
    • Teams requiring API versioning or multi-format responses (e.g., HAL + JSON:API).

Migration Path

  1. Assessment Phase:
    • Audit existing JsonResource classes to identify link generation needs.
    • Test package compatibility with Laravel version and dependencies (e.g., phpunit, spatie/laravel-package-tools).
  2. Pilot Integration:
    • Start with a single resource (e.g., UserResource) to validate link generation.
    • Implement permission-based link filtering (e.g., middleware or resource methods).
  3. Full Rollout:
    • Apply traits to all JsonResource classes.
    • Update API documentation to reflect new link fields (e.g., links.self).
    • Add CI tests for link generation (e.g., assert route existence).

Compatibility

  • Laravel Versions:
    • Officially supports Laravel 5.8–8.x; untested on 9.x+.
    • Workarounds: Patch route resolution logic or fork the package.
  • Dependencies:
    • Requires spatie/laravel-package-tools (v1.x); may conflict with newer Spatie packages.
    • No PHP 8.1+ type hints or attributes (e.g., #[\ReturnTypeWillChange]).
  • Route Customizations:
    • Supports controller-based links but not route model binding for non-standard keys.
    • Manual overrides needed for:
      // Example: Custom route name
      public function links(): array
      {
          return [
              'self' => route('custom.user.show', $this->resource),
          ];
      }
      

Sequencing

  1. Phase 1: Core Integration (2–4 weeks):
    • Add traits to JsonResource classes.
    • Configure links() methods for critical resources (e.g., User, Post).
    • Implement permission checks for sensitive links (e.g., delete).
  2. Phase 2: Testing & Validation (1–2 weeks):
    • Write unit tests for link generation (mock routes).
    • Test edge cases (e.g., missing routes, auth failures).
  3. Phase 3: Documentation & Client Updates (1 week):
    • Update OpenAPI/Swagger specs to include link fields.
    • Notify frontend teams of new response structure.
  4. Phase 4: Deprecation Planning (Ongoing):
    • Monitor for Laravel breaking changes.
    • Evaluate alternatives (e.g., spatie/laravel-hal) for long-term stability.

Operational Impact

Maintenance

  • Pros:
    • Reduced boilerplate: Eliminates manual route() calls in resources.
    • Centralized link management: Changes to routes update automatically in responses.
  • Cons:
    • Abandoned package: No security patches or Laravel updates.
    • Hidden complexity: Link generation logic may obscure route dependencies.
    • Testing burden: Requires route-aware tests to catch regressions.

Support

  • Issues:
    • No official support: Debugging requires community forums or forks.
    • Common problems:
      • Broken links due to route caching or middleware.
      • Permission leaks if links aren’t filtered.
  • Mitigations:
    • Fork the package for critical fixes.
    • Document workarounds (e.g., "Use route() fallback for custom routes").
    • Train devs on debugging link generation (e.g., php artisan route:list).

Scaling

  • Performance:
    • Minimal impact: Link generation adds ~1–5ms per request (negligible for most APIs).
    • Caching: Links can be cached per resource (e.g., Cache::remember()).
  • Complexity:
    • Scalable for standard APIs: Works well with 100+ resources.
    • Non-scalable for dynamic routes: Custom route logic may bloat resources.
  • Database:
    • No direct impact, but route caching (Laravel 10+) may affect link freshness.

Failure Modes

Failure Scenario Impact Mitigation
Laravel version upgrade Package breaks Fork or replace with spatie/laravel-hal
Route caching enabled Stale links Disable caching or implement refresh logic
Missing route Undefined route error Fallback to route() or silent suppression
Permission leak Unauthorized access via links Filter links by user roles in resource
Dependency conflicts Package fails to install Isolate in custom namespace or fork

Ramp-Up

  • Learning Curve:
    • Low for basic use: 1–2 hours to add traits and links() method.
    • High for advanced use: Custom route logic may require deep Laravel routing knowledge.
  • Onboarding:
    • Documentation: Outdated README; supplement with internal guides.
    • Examples: Share working JsonResource snippets for the team.
  • Training:
    • Workshop: Demo link generation and permission filtering.
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