- How do I install Laratheme in Laravel 11/12?
- Run `composer require jcmccoders/laratheme` and publish the config and stubs with `php artisan vendor:publish --tag=theme-config --tag=theme-stubs`. This sets up the `config/theme.php` file and theme stubs in `resources/themes/stubs`. Ensure PHP 8.2+ is installed.
- Can I switch themes dynamically at runtime?
- Yes, Laratheme supports dynamic theme switching via the `THEME_ACTIVE` environment variable or `config/theme.php`. Update the value and clear the Blade cache (`php artisan view:clear`) to apply changes immediately. Avoid hardcoding theme names in your code.
- Does Laratheme work with Laravel Mix or Vite?
- Laratheme assumes assets are pre-compiled and stored in `public/themes/{theme}/`. If using Mix/Vite, ensure your build tool outputs files to this directory. Versioned assets (e.g., hashed filenames) must be manually managed to avoid cache-busting issues.
- How do I create a new theme using Laratheme?
- Use the Artisan command `php artisan make:theme theme-name`. This generates a theme folder with default views (`welcome.blade.php`, `layouts/app.blade.php`) and a corresponding public assets directory. Customize the stubs in `resources/themes/stubs` to modify the default structure.
- Will Laratheme work with Laravel Livewire or Inertia.js?
- Yes, Laratheme integrates seamlessly with Livewire and Inertia.js as long as themes are rendered server-side. For Livewire, ensure your components reference theme assets via `Theme::asset()`. Inertia.js will automatically resolve Blade views from the active theme’s namespace.
- What Laravel versions does Laratheme support?
- Laratheme is officially supported for **Laravel 11 and 12** only. It requires PHP 8.2+ and leverages modern Laravel features like `resource_path()` and `public_path()`. Older Laravel versions (e.g., 10 or below) are not supported.
- How does Laratheme handle shared partials across themes?
- Shared partials (e.g., headers, footers) must be placed in the **active theme’s directory** or a global location outside theme folders. Override them per theme by duplicating the partial in the theme’s views directory. Laratheme does not merge partials automatically.
- Is there a performance impact when switching themes?
- Theme switching itself is lightweight, but dynamic changes may require clearing the Blade cache (`php artisan view:clear`). For high-traffic apps, consider lazy-loading theme assets (e.g., only load CSS/JS for the active theme) or using OPcache to mitigate compilation overhead.
- Can I override middleware or service providers per theme?
- Laratheme does not natively support theme-specific middleware or providers. To achieve this, manually register theme-dependent logic in your `AppServiceProvider` or use Laravel’s middleware groups conditionally based on the active theme (`Theme::active()`).
- Are there security risks with user-controlled themes?
- Laratheme validates the `THEME_ACTIVE` value against allowed themes defined in `config/theme.php`. To prevent path traversal, ensure the `active` config key restricts themes to a whitelist. Asset URLs are sanitized, but always escape dynamic theme paths in Blade templates to avoid XSS.