Installation
composer require emkcloud/livewire-tweak
Ensure your project meets the requirements (Laravel 12/13, Livewire 3.7/4.2, and optionally Livewire Flux).
Environment Setup
Add your custom prefix (e.g., /admin) to .env:
LIVEWIRE_TWEAK_PREFIX=/admin
No config publishing is required unless customizing beyond defaults.
First Use Case
Deploy Livewire components in a load-balanced environment with a custom URL prefix (e.g., yourdomain.com/admin). The package automatically adjusts asset paths and API calls to work seamlessly with the prefix.
Prefix-Aware Livewire Components
/admin) without manual path adjustments./admin/dashboard will generate correct asset URLs like /admin/livewire/livewire.js instead of /livewire/livewire.js.Middleware Integration
LivewireTweakMiddleware) to enforce prefix rules for specific routes or globally.app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
\Emkcloud\LivewireTweak\Middleware\LivewireTweakMiddleware::class,
// ... other middleware
],
];
Flux-Specific Tweaks
LIVEWIRE_TWEAK_FLUX_PREFIX=/backend
Blade Directive Overrides
@livewireStyles and @livewireScripts directives with the package’s tweaks:
@livewireStyles
@livewireScripts
/admin/livewire/livewire.js)./admin, /customers).tenant1.yourdomain.com/admin).http://localhost:8000/admin) to verify asset paths and API calls work correctly.livewire.js?id=1234), so no additional config is needed.Missing Prefix in .env
LIVEWIRE_TWEAK_PREFIX is unset, the package falls back to default behavior (no prefix). Ensure it’s explicitly defined for prefixed environments.LIVEWIRE_TWEAK_PREFIX=/).Conflicting Middleware
TrustedProxy) modifies the request path before LivewireTweakMiddleware runs, prefix adjustments may fail.app/Http/Kernel.php:
$middleware = [
\Emkcloud\LivewireTweak\Middleware\LivewireTweakMiddleware::class,
\GrahamCampbell\TrustedProxy\TrustedProxyMiddleware::class,
// ...
];
Flux-Specific Issues
LIVEWIRE_TWEAK_FLUX_PREFIX if using Flux:
LIVEWIRE_TWEAK_FLUX_PREFIX=/backend
Caching Headaches
Ctrl+F5) when testing prefix changes.Livewire 3 vs. 4
Log Prefix Adjustments Enable debug logging to verify prefix adjustments:
LIVEWIRE_TWEAK_DEBUG=true
Check logs for entries like:
[LivewireTweak] Adjusted Livewire asset path from '/livewire.js' to '/admin/livewire.js'
Inspect Generated HTML
Use browser dev tools to verify @livewireStyles and @livewireScripts output the correct prefixed paths.
API Call Verification
Check Livewire’s internal API calls (e.g., livewire/updates) in the Network tab. Ensure they use the prefixed endpoint (e.g., /admin/livewire/updates).
Custom Prefix Logic Extend the package’s prefix logic by binding your own resolver:
LivewireTweak::extend(function ($request) {
return $request->segment(1) === 'custom' ? '/custom' : config('livewire-tweak.prefix');
});
Middleware Customization Override the default middleware behavior by publishing and modifying the config:
php artisan vendor:publish --tag=livewire-tweak:config
Then extend LivewireTweakMiddleware in app/Http/Middleware/LivewireTweakMiddleware.php.
Blade Directive Overrides Register custom Blade directives that leverage the package’s prefix logic:
Blade::directive('customLivewireScripts', function () {
return "<?php echo \\Emkcloud\\LivewireTweak\\LivewireTweak::scripts(); ?>";
});
How can I help you explore Laravel packages today?