- How do I set up @aliases in Laravel using this package?
- Install via Composer (`composer require craftcms/laravel-aliases`), then register the service provider in `AppServiceProvider.php` by adding `$this->app->register(AliasesServiceProvider::class)`. Define aliases in your config (e.g., `'aliases' => ['@web' => base_path('web')]`) and use them with the `alias()` helper or `config('aliases.web')` in paths/URLs.
- Does this package work with Laravel 10 and PHP 8.1+?
- Yes, the package is confirmed compatible with Laravel 10+ and PHP 8.1+. However, test thoroughly in your environment, as dependency conflicts or subtle behavioral differences with Yii’s `yiisoft/aliases` could arise. Downgrade support for older Laravel versions isn’t guaranteed.
- Can I use this for dynamic runtime aliasing, like plugin systems?
- Yes, this package excels at dynamic aliasing—ideal for plugin systems or modular apps where namespaces or paths change at runtime. For example, you can bind aliases dynamically via Laravel’s service container (e.g., `app->bindAlias('plugins', fn() => plugin_path())`).
- What’s the difference between this and Laravel’s native autoloader?
- This package provides *runtime* alias resolution (e.g., `@web` resolving to `public_path()`), while Laravel’s native autoloader handles *class* namespace resolution via `composer.json`. Use this for path/URL aliases, not autoloading conflicts. For most cases, Laravel’s built-in solutions suffice, but this is useful for Yii migrations or hybrid apps.
- Is this package actively maintained? What if it breaks?
- The package lacks visible maintenance activity (no stars/issues/recent updates) despite its 2026 release date, which is a red flag. If abandoned, consider forking it or replacing it with a custom solution (e.g., a `SplAutoloaderRegister` extension). Always test in staging and document fallbacks.
- How do I test alias resolution in my Laravel app?
- Write unit tests using Laravel’s `app()` helper to verify alias resolution. For example, test `app('aliases')->get('@web')` matches expected paths. Edge cases like circular aliases or case sensitivity should also be validated. Use PHPUnit’s `refreshApplication()` to reset the container between tests.
- Will this slow down my Laravel application?
- The performance impact is minimal for most use cases, as alias resolution is lightweight. However, dynamic aliasing in high-throughput systems (e.g., API facades) could introduce micro-overhead. Benchmark critical paths if performance is a concern, and consider caching resolved aliases if needed.
- Can I use this for migrating from Yii to Laravel?
- Yes, this package bridges Yii and Laravel by wrapping `yiisoft/aliases`, making it ideal for incremental migrations. Replace Yii’s `Yii::getAlias()` calls with Laravel’s `alias()` helper or `config('aliases.@yii')`. Test thoroughly, as subtle differences in alias behavior may exist between the two frameworks.
- Are there alternatives to this package for Laravel?
- For path/URL aliases, Laravel’s native `mix()` or `public_path()` helpers often suffice. For namespace aliasing, use Composer’s `autoload.psr-4` or `classmap`. If you need dynamic runtime aliases, consider a custom solution (e.g., a service provider with `app->bind()`) or forking this package for maintenance.
- How do I handle environment-specific aliases (e.g., dev vs. prod paths)?
- Define aliases in your `.env` file (e.g., `ALIAS_WEB=public_html`) and load them in `AppServiceProvider::boot()` using `config(['aliases' => ['@web' => env('ALIAS_WEB')]])`. This ensures paths adapt to each environment without hardcoding. Combine with Laravel’s `config()` caching for performance.