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

Filament Single Record Resource Laravel Package

coringawc/filament-single-record-resource

Implements the single-record resource pattern for Filament. Replace index lists with a per-user “one record” resource (Profile, Settings, Wallet, Subscription). Traits handle routing, navigation, auth fallbacks, record resolution, and nested breadcrumbs.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Single-record pattern alignment: Perfectly fits Laravel/Filament’s admin panel use cases (e.g., "My Profile," "My Wallet") where a 1:1 user-to-record relationship exists. Eliminates boilerplate for redirecting index to view and handling authorization.
  • Nested resource support: Seamlessly integrates with Filament’s nested resource hierarchy (e.g., Wallet → Companies → Products), preserving breadcrumbs and URL consistency without exposing parent IDs.
  • Contract-driven design: The SingleRecordResolvableResource interface enables static analysis and IDE support, reducing runtime errors and improving maintainability.
  • Authorization flexibility: Overrides Filament’s default viewAny() behavior to allow record-level access even when collection-level permissions are denied, aligning with SaaS/multi-tenant architectures.

Integration Feasibility

  • Low friction: Requires minimal changes—replace index pages with view/edit pages and add two traits (HasSingleRecordResource to the Resource, HasSingleRecord to pages). No database migrations or complex refactoring.
  • Backward compatibility: Works with legacy Resources lacking the contract, though adopting SingleRecordResolvableResource is recommended for new projects.
  • Filament version agnostic: Supports Filament 4/5 and Laravel’s supported versions, reducing version-locking risks.

Technical Risk

  • Authorization edge cases: Custom resolution logic (e.g., firstOrCreate) may introduce race conditions or inconsistent state if not idempotent. Requires validation in CI/CD.
  • Nested resource complexity: Deeply nested single-record chains (e.g., 4+ levels) may require explicit query scoping to avoid performance degradation. Profile queries in staging.
  • Testing overhead: Unit tests for custom resolvers (e.g., resolveSingleRecord()) must cover edge cases like:
    • Authenticated user = null
    • Record resolution failures (e.g., firstOrCreate conflicts)
    • Authorization policy conflicts (viewAny vs. view permissions).
  • Dependency bloat: Adds ~200 LOC to the codebase. Justify with usage frequency (e.g., >3 single-record resources).

Key Questions

  1. Use case validation:
    • Are all target resources truly 1:1 with users/tenants? If not, consider hybrid patterns (e.g., index + single-record fallback).
    • Will nested resources exceed 3 levels? If so, benchmark query performance with/without the package.
  2. Authorization strategy:
    • Should viewAny always be denied for single-record resources? If yes, document this as a team convention.
    • Are there policies where viewAny = false but view = true for specific roles? Test thoroughly.
  3. Customization needs:
    • Will custom resolvers (e.g., firstOrCreate) require transactional guarantees? If yes, wrap in a service layer.
    • Are breadcrumbs for nested resources critical? If so, validate the package’s normalization logic against your design system.
  4. Long-term maintenance:
    • How will this interact with future Filament major versions? Pin to a compatible branch (e.g., 5.x) and monitor deprecations.
    • Should the contract (SingleRecordResolvableResource) be enforced via static analysis (e.g., PHPStan)? If yes, add to your baseline rules.

Integration Approach

Stack Fit

  • Primary stack: Laravel 10/11 + Filament 4/5. No additional dependencies beyond Composer.
  • Secondary stack:
    • Multi-tenancy: Works with packages like stancl/tenancy if the resolver logic accounts for tenant context (e.g., where('tenant_id', tenant()->id)).
    • Testing: Integrates with Pest/Testbench (validated in CI). Use filament/testing for auth stubs in tests.
    • CI/CD: Add a lint step for SingleRecordResolvableResource adoption (if enforcing the contract).

Migration Path

  1. Assessment phase (1–2 days):
    • Audit existing Resources to identify candidates for single-record conversion.
    • Document current authorization logic (e.g., viewAny policies) for comparison.
  2. Pilot implementation (3–5 days):
    • Convert 1–2 low-risk Resources (e.g., "My Profile") using the package.
    • Test edge cases: auth changes, nested resources, custom resolvers.
  3. Full rollout (1–2 sprints):
    • Replace index pages with view/edit pages across the codebase.
    • Update navigation menus to reflect the new URL structure (e.g., /profile instead of /profile/index).
    • Deprecate legacy Resources via feature flags if needed.

Compatibility

  • Filament plugins: May conflict if they assume index pages exist. Test with plugins like filament-spatie-laravel-permission or filament-activity-log.
  • Custom middleware: Ensure middleware (e.g., route guards) doesn’t block view routes for single-record Resources.
  • URL generation: Use getUrl() or getViewUrl() instead of hardcoding /index in links/redirects.

Sequencing

  1. Start with root Resources (e.g., "My Wallet") before nested ones.
  2. Prioritize Resources with simple resolvers (e.g., belongsTo(user)) over complex ones (e.g., firstOrCreate).
  3. Test authorization flows last—this is the highest risk area.
  4. Nested resources: Implement parent-child chains in parallel to validate breadcrumb logic.

Operational Impact

Maintenance

  • Pros:
    • Reduces future tech debt by standardizing single-record patterns.
    • Centralized resolver logic (e.g., in resolveSingleRecordBuilder) is easier to update than scattered index page logic.
  • Cons:
    • Custom resolvers may require updates if business rules change (e.g., wallet creation logic).
    • Debugging nested resource issues (e.g., breadcrumbs) may require deeper Filament knowledge.
  • Tooling:
    • Add a custom PHPStan rule to enforce SingleRecordResolvableResource adoption.
    • Document resolver patterns (e.g., "Use firstOrCreate only in services") in the team’s architecture decision records (ADRs).

Support

  • Common issues:
    • "Why can’t I access my single-record resource?" → Check viewAny/view policies and resolver logic.
    • "Nested resource URLs are broken." → Validate isNestedResource() and query scoping.
    • "Breadcrumbs are incorrect." → Ensure parent Resources implement the contract.
  • Documentation:
    • Create a runbook for:
      1. Adding a new single-record Resource.
      2. Debugging authorization failures.
      3. Customizing resolvers for edge cases.
    • Example: A "Troubleshooting Guide" with commands like:
      # Check resolver output in Tinker
      app(\App\Filament\Resources\MyWalletResource::class)->resolveSingleRecord()
      

Scaling

  • Performance:
    • Query optimization: Custom resolvers should avoid N+1 queries. Use with() or eager loading in resolveSingleRecordBuilder.
    • Caching: Cache resolved records if they rarely change (e.g., user profile). Use filament()->cache() or Laravel’s cache.
    • Load testing: Simulate concurrent access to single-record Resources (e.g., "My Settings") to validate resolver performance.
  • Team scaling:
    • Onboard new devs with a "Single-Record Resource" template (Resource + view/edit pages).
    • Use the contract (SingleRecordResolvableResource) to reduce onboarding time for complex resolvers.

Failure Modes

Failure Scenario Impact Mitigation
Resolver returns null Broken UI/404 Add @throws docs and validate in tests. Use resolveSingleRecordOrFail().
Authorization conflict (viewAny=false, view=true) Access denied for valid users Test with filament:test and adjust policies.
Nested resource URL misrouting Inconsistent navigation Use getUrl() and validate isNestedResource() logic.
Race condition in firstOrCreate Duplicate records Wrap in transactions or use upsert.
Filament major version upgrade Package compatibility issues Pin to a branch (e.g., 5.x) and monitor Filament’s changelog.

Ramp-Up

  • For developers:
    • Training: 1-hour workshop covering:
      • Traits vs. contracts (HasSingleRecordResource vs. SingleRecordResolvableResource).
      • Resolver patterns (builder vs. custom method).
      • Debugging tips (e.g., filament()->auth()->user() stubs in tests).
    • Checklist: Provide a "Single-Record Resource" template with:
      // Resource.php
      use HasSingleRecord
      
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime