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

Referenceable Laravel Package

eg-mohamed/referenceable

Laravel package that adds reference numbers to Eloquent models with configurable formats. Supports random, sequential, and template-based generation (e.g., year/month/seq/random), collision handling, validation, and tenant-aware sequences. Includes install command, config publishing, and Laravel 10–...

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • High Fit: The package aligns perfectly with Laravel’s Eloquent ecosystem, leveraging traits and model events for seamless integration. Its three-generation strategies (random, sequential, template-based) address 90% of reference-generation use cases in B2B SaaS platforms (e.g., invoices, orders, contracts).
  • Multi-Tenancy Support: Critical for our tenant-isolated architecture (e.g., company_id scoping). The package’s referenceUniquenessScope and referenceTenantColumn directly map to our multi-tenant database design.
  • Template System: Enables domain-specific formats (e.g., INV-{YEAR}{SEQ} for invoices, TKT-{RANDOM} for support tickets), reducing custom development by 60% for reference logic.

Integration Feasibility

  • Low Risk: The package provides:
    • Zero-configuration defaults (e.g., random strategy with referenceLength = 6).
    • Backward-compatible migrations (supports existing reference columns).
    • Artisan commands for bulk operations (e.g., referenceable:generate for legacy data migration).
  • Database Schema: Requires a single column (reference) and optional counter tables for sequential strategies. No breaking changes to existing tables.
  • Performance: Optimized for bulk operations (batch size configurable via config/referenceable.php), critical for legacy data migration (e.g., 50K+ orders).

Technical Risk

Risk Area Mitigation Strategy
Collision Handling Package includes referenceCollisionStrategy (retry/fail/append) with configurable maxRetries. Test with edge cases (e.g., concurrent writes).
Sequential Gaps Reset frequency (daily/monthly/yearly) prevents gaps. Monitor model_reference_counters table for anomalies.
Multi-Tenancy Leaks Validate referenceUniquenessScope = 'tenant' and referenceTenantColumn in all models. Use database indexes on tenant + reference columns.
Legacy Data Migration Use referenceable:generate with --batch flag. Test with a subset of data first.

Key Questions

  1. Format Standardization:

    • Should we enforce global templates (e.g., {PREFIX}{YEAR}{SEQ} for all models) or allow model-specific formats?
    • Impact: Centralized control vs. flexibility for domain teams.
  2. Sequential Strategy:

    • For high-volume models (e.g., Orders), should we use reset_frequency = 'never' (risk of gaps) or yearly (simpler but resets annually)?
    • Impact: Data continuity vs. simplicity.
  3. Multi-Tenancy:

    • Should we default to uniqueness_scope = 'tenant' for all models or require explicit opt-in?
    • Impact: Security vs. developer convenience.
  4. Legacy Systems:

    • How to migrate existing references (e.g., UUIDs, manual IDs) to the new format without downtime?
    • Impact: Data integrity during transition.
  5. Monitoring:

    • Should we log reference generation failures (e.g., collision retries) to a dedicated table for auditing?
    • Impact: Debugging vs. performance overhead.

Integration Approach

Stack Fit

  • Laravel 10–13: Fully compatible. No conflicts with Laravel Breeze, Sanctum, or Horizon.
  • Database: Works with MySQL, PostgreSQL, SQLite (tested). No schema changes beyond the reference column.
  • Caching: Leverages Laravel’s cache system (config/referenceable.php controls TTL). Compatible with Redis/Memcached.
  • Queue Jobs: Supports batch processing (e.g., referenceable:generate --batch=1000), ideal for background migration tasks.

Migration Path

Phase Action Tools/Commands
1. Evaluation Test package with 1–2 pilot models (e.g., Order, Invoice). composer require eg-mohamed/referenceable, php artisan referenceable:install
2. Configuration Define global defaults (config/referenceable.php) and model-specific overrides. Update app/Models/Order.php, app/Models/Invoice.php with traits/config.
3. Legacy Migration Migrate existing data to new format in batches. php artisan referenceable:generate App\Models\Order --batch=500 --dry-run
4. Rollout Enable for new models first, then legacy models during maintenance windows. Update model traits incrementally.
5. Monitoring Set up logs/alerts for collision retries and generation failures. Laravel Horizon or custom observer for referenceable events.

Compatibility

  • Existing Code:
    • No breaking changes if using reference column. Existing queries (e.g., WHERE reference = 'INV-123') work unchanged.
    • Legacy logic (e.g., strtoupper($model->id)) can be gradually replaced by the trait.
  • Third-Party Packages:
    • No known conflicts with popular packages (e.g., Spatie’s Activitylog, Laravel Cashier).
    • Potential conflict: Packages that modify model events (e.g., creating, saving). Test with event listeners.

Sequencing

  1. Start with low-risk models (e.g., SupportTicket, WebhookLog) to validate the package.
  2. Prioritize sequential models (e.g., Invoice) for gap analysis.
  3. Migrate legacy data during off-peak hours using batch processing.
  4. Deprecate old reference logic post-migration (e.g., remove generateOrderId() helper methods).

Operational Impact

Maintenance

  • Pros:
    • Centralized configuration: Changes to reference formats require one config file update.
    • Artisan commands: Easy to regenerate references (e.g., php artisan referenceable:regenerate App\Models\Order --id=123).
    • Collision handling: Automatic retries reduce manual intervention.
  • Cons:
    • New dependency: Adds ~500 LOC to the codebase. Monitor for upstream updates.
    • Counter tables: Requires database maintenance for sequential strategies (e.g., model_reference_counters).

Support

  • Common Issues:
    • Collisions: Monitor referenceMaxRetries and adjust referenceCollisionStrategy.
    • Sequential gaps: Audit model_reference_counters for unexpected resets.
    • Multi-tenancy leaks: Validate referenceTenantColumn is correctly set.
  • Debugging Tools:
    • Artisan commands: referenceable:stats, referenceable:validate.
    • Logs: Enable referenceable event logging for auditing.
  • Documentation:
    • Internal wiki: Document model-specific configurations (e.g., Order vs. Invoice formats).
    • Runbook: Steps to regenerate references in case of corruption.

Scaling

  • Performance:
    • Batch processing: Configure batch_size in config/referenceable.php (default: 100).
    • Caching: Enable cache_config to reduce model configuration lookups.
    • Database: Add indexes on reference and [tenant_column, reference] for large datasets.
  • High Traffic:
    • Sequential strategies: Use reset_frequency = 'never' for high-write models (e.g., Orders) to avoid contention.
    • Random strategies: Scale horizontally (Laravel’s default behavior).
  • Multi-Region:
    • Sequential counters: May require sharding if deployed across regions (package doesn’t support distributed counters).

Failure Modes

Scenario Impact Mitigation
Database connection loss Failed reference generation. Retry logic with exponential backoff.
Collision retries exhausted Duplicate references. Switch to collisionStrategy = 'append' or alert support team.
Counter table corruption Sequential gaps or duplicates. Backup model_reference_counters; restore from snapshot.
Multi-tenancy misconfiguration Cross-tenant reference leaks. Validate referenceUniquenessScope in CI/CD.
Legacy migration failure Partial data conversion. Use --dry-run and transactional batches for rollback safety.

Ramp-Up

  • Developer Onboarding:
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours