- How do I install Laravel Multi Domain in a Laravel 12+ project?
- Run `composer require gecche/laravel-multidomain:12.*` (or `13.*` for Laravel 13). Then override `bootstrap/app.php` and `config/app.php` as per the README, publish the config with `php artisan vendor:publish`, and add your domains to `config/multidomain.php`. The package handles the rest at runtime.
- Can I use this package with subdomains like tenant1.example.com?
- Yes, but you’ll need to customize the `domain_detection_function_web` in `config/multidomain.php` to parse subdomains. The default relies on `$_SERVER['SERVER_NAME']`, so regex or string manipulation may be needed for dynamic tenant IDs. Test thoroughly with your DNS setup.
- Will this work with Laravel Forge or shared hosting?
- Yes, but ensure your server passes the correct `SERVER_NAME` or `HTTP_HOST` to PHP. If using Docker or load balancers, override `domain_detection_function_web` to handle proxied headers like `X-Forwarded-Host`. The package includes fallback logic for edge cases.
- How do I configure per-domain databases?
- Create `.env` files named `.env-domain.com` (e.g., `.env-site1.com`) with your database credentials. The package automatically loads the correct `.env` based on the domain. For complex setups, use `config/multidomain.php` to map domains to custom database connections.
- Does this package support Laravel Horizon for queues?
- Horizon requires manual configuration due to its tight coupling with Laravel’s queue system. You’ll need to override Horizon’s `ConnectionResolver` or use separate queue tables/workers per domain (e.g., `default_site1`, `default_site2`). The README provides workarounds, but test thoroughly in staging.
- How do I handle storage paths like `storage/app/site1`?
- The package overrides `storage_path()` to append the domain (e.g., `storage/app/site1.com`). For `storage:link`, manually create symlinks or use a post-install script. If using S3, scope buckets/paths per domain in your `.env` files or via `config/filesystems.php`.
- What’s the performance impact of loading per-domain configs?
- Minimal for small-scale deployments. The package caches domain configs after the first request. For high-traffic apps with 100+ domains, pre-cache configs with `php artisan config:cache --domain=site1.com` or use a database-driven config store to reduce I/O.
- Can I use this with Laravel Vapor or serverless?
- Yes, but ensure your deployment platform passes the correct domain to PHP (e.g., via `X-Forwarded-Host`). For Vapor, configure the `domain_detection_function_web` to parse Lambda context or custom headers. Test with `artisan --domain=site1.com` to simulate serverless environments.
- What happens if a domain isn’t configured?
- The package falls back to the default domain (e.g., `localhost`) or throws a `DomainNotFoundException` if no fallback is set. Configure a default in `config/multidomain.php` or handle exceptions in your `AppServiceProvider` for graceful degradation.
- Are there alternatives for multi-tenant Laravel apps?
- For database-per-tenant setups, consider `stancl/tenancy` (supports UUIDs, subdomains, and shared databases). For simpler cases, `spatie/laravel-multitenancy` offers similar domain-based isolation. Choose based on your needs: this package excels at domain-driven isolation, while others support tenant IDs or shared databases.