sindyko/aliaser
Laravel package for elegant alias management across Eloquent models, Livewire forms, DTOs, collections, and enums. Use short aliases and the Entity facade (Entity::user(1)), auto-sync morph maps, and optimize Livewire snapshots with custom synthesizers.
Entity facade to abstract model access. The ModelProxy pattern enables seamless integration with query builder methods while maintaining compatibility with static methods (e.g., create(), all()).ModelAliasSynth, FormAliasSynth, etc.) addresses a critical pain point in Livewire-heavy applications. The morph map integration further reduces payload size in polymorphic relations.ModelRegistry, FormRegistry, etc.) enforce type safety and bidirectional mapping (alias ↔ class), reducing boilerplate in controllers and services.aliaser:list, aliaser:install) streamline alias management, aligning with Laravel’s convention-over-configuration philosophy.AppServiceProvider registration, with zero breaking changes to existing Eloquent/Livewire code.Entity facade wraps native model calls, ensuring existing queries (e.g., User::where(...)) remain functional. Livewire snapshots are opt-in via synthesizers.commentable_type: 'post' instead of 'App\Models\Post'), reducing database bloat without manual migration.allow_overwrite: true, duplicate aliases throw exceptions. Mitigation: Enforce naming conventions (e.g., snake_case) and validate during CI.aliaser:list --json to audit aliases pre-deployment.Alias Naming Strategy:
user vs. app_user)? Document conventions to avoid collisions.user, post) and reserve prefixes (e.g., admin_) for namespaces.Livewire Adoption:
modelsMap() and objectsMap(), then enable Livewire features incrementally.Morph Map Trade-offs:
post) or FQCNs? Aliases reduce storage but may complicate debugging.use_morph_map: true in config and monitor query performance.Migration Path:
User::find() with Entity::user(1)?Security:
mdl-alias keys) and avoid exposing raw aliases in API responses.spatie/laravel-data or ramsey/uuid for structured data.ModelProxy::clearStaticMethodsCache().Phase 1: Core Aliases (2–4 weeks)
modelsMap()) and DTOs (objectsMap()) in AppServiceProvider.User::find()) with Entity::user() in controllers/services.aliaser:list to audit coverage.Phase 2: Livewire Optimization (1–2 weeks)
class: "user" instead of "App\Models\User").php artisan livewire:test.Phase 3: Polymorphic Relations (1 week)
use_morph_map: true in config/aliaser.php.toArray()/toJson() unless explicitly used in responses.| Step | Action | Dependencies | Risk |
|---|---|---|---|
| 1 | Install package | Laravel 10+ | Low |
| 2 | Register aliases in AppServiceProvider |
- | Low |
| 3 | Replace Model::method() with Entity::alias() |
- | Medium (refactoring) |
| 4 | Enable Livewire synthesizers | Livewire 3.x | Medium (snapshot tests) |
| 5 | Enable morph map sync | - | Low |
| 6 | Update CI/CD to validate aliases | - | Low |
AppServiceProvider or separate config file (e.g., config/aliaser.php).App\Models\User → App\Models\Customer).aliasForClass() to dynamically fetch aliases and CI checks to detect orphaned aliases.aliaser:list --json to track aliases and feature flags for gradual rollout.aliaser:help provides topic-specific documentation.Entity::user(1) → App\Models\User).type columns reduce storage (e.g., post vs. App\Models\Post).| Scenario | Impact | Mitigation |
|---|---|---|
| Alias collision | AliaserException breaks application |
Enable allow_overwrite: true in |
How can I help you explore Laravel packages today?