Weave 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 Apiable Laravel Package

open-southeners/laravel-apiable

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • JSON:API Alignment: The package enforces JSON:API standards (resource naming, relationships, pagination, sparse fieldsets), which remains ideal for API-first Laravel projects requiring strict contract compliance. Release 4.5.0 strengthens this by fixing sparse fieldsets so primary, foreign, and morph keys required for Eloquent hydration are retained internally but excluded from response attributes—closing a prior correctness gap for relationship-heavy APIs.
  • Laravel Ecosystem Synergy: Built for Laravel, it integrates with Eloquent models, API resources, and Lumen (partial). Leverages Laravel’s service container and events for extensibility. 4.5.0 makes collections and paginated responses consult Apiable::modelResourceMap() for every model, matching single-resource behavior—improving parity across response shapes.
  • Domain-Driven Design (DDD) Support: Encourages resource-oriented design. 4.5.0’s per-model resource resolution in mixed-model collections supports polymorphic and modular monolith boundaries without custom collection serializers.
  • Query Capability Expansion: New AllowedFilter::notEqual() / notLike() negated filters add server-driven filtering expressiveness, reducing the need for bespoke endpoints or GraphQL-like workarounds for exclusion queries. Comma-separated negated values combine with AND, a contract detail clients must understand.
  • Alternatives Comparison:
    • Fractal: More flexible but requires manual JSON:API compliance and custom filter plumbing.
    • Spatie’s Laravel API Resources: Lacks built-in JSON:API validation.
    • This package: Opinionated but enforces standards out-of-the-box, now with broader filtering and mixed-model collection support.

Integration Feasibility

  • Low-Coupling: Designed as a drop-in solution for existing Laravel APIs. Minimal refactoring if using API resources (Laravel 8+). 4.5.0 is additive/fix-only—no breaking changes or deprecations called out—so upgrade risk is low.
  • Migration Path:
    • Phase 1: Replace custom JSON responses with Apiable::resource().
    • Phase 2: Enforce JSON:API compliance (links, meta, included relationships).
    • Phase 3: Leverage custom serializers/transformers for complex data.
    • Phase 4 (new): Adopt negated filters selectively and register models in modelResourceMap() where mixed-model collections exist.
  • Backward Compatibility: Supports Laravel 9.x/10.x, PHP 8.1+. 4.5.0 preserves existing semantics; the duplicate-default-filter fix changes prior buggy behavior (scalar becoming a duplicate array) to idempotent behavior—teams relying on the broken output should verify tests.
  • Mixed-Model Collections: Explicitly supplied resource classes still take precedence over modelResourceMap(), preserving override paths for edge cases.

Technical Risk

Risk Area Mitigation Strategy
Schema Drift Use apiable:validate Artisan command to catch compliance issues early.
Performance Overhead Benchmark relationship loading (eager loading vs. Apiable::with()).
Custom Logic Conflicts Extend via ApiableServiceProvider or override default behaviors.
Deprecation Risk Monitor Laravel version support; fork if needed (MIT license allows modification).
Testing Complexity Use PestPHP or PHPUnit to test JSON:API responses with ApiableTestCase.
Sparse Fieldset Regression Add explicit tests asserting internal hydration keys never leak into attributes while requested appends remain visible.
Filter Semantics Drift Document that comma-separated negated values combine with AND; add contract tests for notEqual/notLike.
Collection Resource Mapping Verify modelResourceMap() coverage for every model in mixed collections; confirm explicit resource precedence.
Duplicate Filter Config Benefit from 4.5.0 idempotency; remove now-unnecessary defensive workarounds.

Key Questions

  1. API Contract Enforcement:
    • How strictly must the team adhere to JSON:API (e.g., id fields, singular resource names)?
    • Will clients depend on the prior sparse-fieldset behavior or on previously duplicated default filter arrays?
  2. Filter Operator Contract:
    • Which endpoints should expose negated filters, and is AND-combined comma-separated negation the expected client contract?
  3. Relationship Handling:
    • Are there nested resources or polymorphic relationships requiring modelResourceMap() registration and sparse-fieldset regression tests?
  4. Pagination Strategy:
    • Does the team prefer offset/limit or cursor-based pagination? (Package supports both; negated filters may stress offset scans.)
  5. Error Handling:
    • How will 422 Unprocessable Entity responses be standardized?
  6. Authentication/Authorization:
    • Will APIable’s built-in policy integration suffice, or are custom guards needed?
  7. Documentation Gaps:
    • Are negated filter semantics, mixed-model collection mapping, and sparse-fieldset append visibility documented for client teams?

Integration Approach

Stack Fit

Component Compatibility
Laravel Core 9.x/10.x (PHP 8.1+).
Eloquent Models Full support (uses Apiable trait).
API Resources Replaces or extends JsonResource.
Lumen Partial support (check for missing Laravel-specific features).
Testing Works with Laravel testing helpers (assertJsonApiFragment).
Caching Supports Apiable::cache() for serialized responses.
Validation Integrates with Laravel’s Form Requests for input validation.
Filtering (4.5.0) AllowedFilter::notEqual() / notLike(); comma-separated negated values combine with AND.
Mixed-Model Collections (4.5.0) Per-model resolution via modelResourceMap(); explicit resource class wins.

Migration Path

  1. Assessment Phase:
    • Audit existing API endpoints for JSON:API compliance.
    • Identify non-compliant responses (arrays instead of objects, missing links).
    • Inventory endpoints using sparse fieldsets, mixed-model collections, and duplicate default filters.
  2. Incremental Rollout:
    • Step 1: Add use Apiable; to Eloquent models and replace JsonResource with ApiableResource.
    • Step 2: Update controllers to return Apiable::resource() instead of raw JSON.
    • Step 3: Enable relationship loading (Apiable::with('posts')).
    • Step 4 (new): Register models in modelResourceMap() where collections span multiple models.
    • Step 5 (new): Introduce negated filters endpoint-by-endpoint behind contract tests.
  3. Validation Phase:
    • Run php artisan apiable:validate to catch issues.
    • Fix schema violations (plural resource names, missing type fields).
    • Add regression tests for sparse-fieldset hydration keys and append visibility.
  4. Optimization Phase:
    • Implement caching for frequently accessed resources.
    • Customize serializers for complex data structures.
    • Review query plans for notEqual/notLike filters; add indexes where selective.

Compatibility

  • Pros:
    • Zero-config for basic JSON:API compliance.
    • First-class Laravel integration (service providers, events, commands).
    • Extensible via traits, macros, and service providers.
    • 4.5.0 is non-breaking; fixes improve correctness for sparse fieldsets, collections, and filter configuration.
  • Cons:
    • Opinionated: May require overrides for non-standard APIs.
    • Laravel-only: Not suitable for non-Laravel PHP projects.
    • Limited Lumen Support: Some features (e.g., Horizon queues) may not apply.
    • Negated filters may be less index-friendly and need performance review.

Sequencing

Priority Task Dependencies
1 Upgrade to 4.5.0; run full API contract regression suite. None
2 Replace JsonResource with ApiableResource in core models. Existing API resources.
3 Update controllers to use Apiable::resource(). Step 2.
4 Enable relationships and pagination. Step 3.
5 Register modelResourceMap() for mixed-model collections. Step 3.
6 Validate compliance with apiable:validate. Steps 1–5.
7 Adopt notEqual/notLike filters with contract and performance tests. Step 6.
8 Customize serializers/transformers for edge cases. Step 6.
9 Implement caching and performance tuning. Step 8.

Operational Impact

Maintenance

  • Proactive:
    • Artisan Commands: apiable:validate, apiable:publish (config overrides).
    • Testing: Built-in assertJsonApiFragment; add targeted tests for 4.5.0 behaviors (sparse-fieldset key retention, mixed-model collection mapping, idempotent default filters).
  • Reactive:
    • Monitoring: Track JSON:API compliance via CI/CD (fail builds on schema violations).
    • Logging: Use Laravel logging to debug relationship loading and filter construction.
  • Configuration Hygiene: 4.5.0 removes the duplicate-default-filter footgun, reducing defensive config reviews.
  • Upgrade Path:
    • Follow Laravel’s release cycle; 4.5.0 is a low-risk minor upgrade. MIT license permits forking.

Support

  • Documentation:
    • Official Docs: Comprehensive but assumes Laravel familiarity.
    • Gaps: Examples for nested resources, custom meta fields, and the exact AND semantics of negated comma-separated filters may lag the release.
  • Community:
    • GitHub Issues: Small but active project; 4.5.0 demonstrates ongoing maintenance.
    • Partners: Skore (commercial support) may offer enterprise assistance.
  • Troubleshooting:
    • Common issues: circular references, deeply nested relationships, pagination conflicts.
    • New: verify modelResourceMap() registration when collection items serialize with unexpected types.
    • Debug with dd(Apiable::toArray($resource)) to inspect serialization.

Scaling

  • Performance:
    • Relationship Loading: Use Apiable::with() judiciously to avoid N+1 queries.
    • Caching: Leverage Apiable::cache() for static or rarely changing data.
    • Pagination: Cursor-based pagination scales better than offset/limit for large datasets.
    • Negated Filters: != and NOT LIKE can bypass indexes and force scans; gate exposure to high-cardinality endpoints and benchmark before broad rollout.
  • Horizontal Scaling:
    • Stateless by design; works with queue workers.
    • Rate Limiting: Integrate Laravel’s throttle middleware for APIable endpoints.
  • Database Load:
    • Selective Fieldsets: Use fields() to reduce payload size; 4.5.0 ensures hydration keys don’t inflate the response.
    • Lazy Loading: Avoid Apiable::load('*'); specify only needed relationships.
    • Collection Mapping: modelResourceMap() lookups are per-model; verify no material overhead in large mixed collections.

Failure Modes

Scenario Impact Mitigation
Schema Violation API clients reject malformed responses. Use apiable:validate in CI/CD.
Circular References Infinite loops in serialization. Configure Apiable::ignore() or use Apiable::maxDepth().
Relationship Overfetching High DB load. Use Apiable::with() selectively.
Cache Stale Data Inconsistent responses. Set short TTLs or use cache tags.
Laravel Upgrade Issues Package compatibility breaks. Test on staging; fork if needed.
Negated Filter Cost Slow queries / full scans from != / NOT LIKE. Restrict operators by endpoint; index review; benchmark.
Missing Collection Mapping Mixed-model collections serialize with wrong type. Register every model in modelResourceMap(); add contract tests.
Sparse Fieldset Leakage Internal keys exposed or relationships fail to hydrate. Regression tests post-4.5.0; assert attributes and included relationships.
Duplicate Filter Config Empty queries from duplicated scalar filters (pre-4.5.0). Upgrade to 4.5.0; remove workarounds; add config tests.

Ramp-Up

  • Onboarding Time:
    • Developers: 1–2 days to migrate core resources; longer for complex APIs.
    • 4.5.0 Delta: ~0.5 day to validate upgrade, register modelResourceMap() entries, and add filter/sparse-fieldset regression tests. Negated filter adoption can be phased per endpoint with minimal client coordination.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
cgv/localized-resource