Installation
composer require devrabiul/livewire-doctor
Publish the config (optional):
php artisan vendor:publish --provider="Devrabiul\LivewireDoctor\LivewireDoctorServiceProvider"
First Command Run a full scan of your Livewire components:
php artisan livewire:doctor:scan
This generates a report in storage/logs/livewire-doctor.log and outputs a summary in the terminal.
Quick Fixes
Use the fix command to auto-correct common issues:
php artisan livewire:doctor:fix
Confirm changes when prompted.
Debugging a Livewire component that fails silently
php artisan livewire:doctor:scan to identify missing assets, invalid directives, or property mismatches.php artisan livewire:doctor:fix to auto-correct issues like:
@js, @vite directives).public arrays.wire:model bindings.Pre-Commit Hook
Add to .git/hooks/pre-commit (or use Laravel Pint/Forge):
php artisan livewire:doctor:scan --quiet
Exit with error if critical issues are found.
CI/CD Pipeline Run in GitHub Actions/Laravel Forge:
- name: Livewire Doctor Scan
run: php artisan livewire:doctor:scan --format=json > livewire-report.json
Parse the JSON output to block merges if issues exceed thresholds.
Onboarding New Developers
Include in README.md:
## Livewire Best Practices
Run `php artisan livewire:doctor:scan` to auto-detect and fix common issues.
Asset Management
Use livewire:doctor:scan --assets to flag missing @js, @vite, or @push directives.
Fix with:
php artisan livewire:doctor:fix --assets
Property Validation
Detect public properties not declared in $rules or $listen:
php artisan livewire:doctor:scan --properties
Component Dependencies Check for orphaned components (unused or circular dependencies):
php artisan livewire:doctor:scan --components
Laravel Forge Add a cron job to run weekly scans:
* * * * * cd /path/to/project && php artisan livewire:doctor:scan --quiet --email=team@example.com
Laravel Telescope Extend Telescope to log LivewireDoctor findings:
LivewireDoctor::extend(function ($report) {
Telescope::logs()->create([
'message' => 'LivewireDoctor: ' . $report->summary(),
'level' => 'info',
]);
});
Custom Rules
Extend the scanner in app/Providers/LivewireDoctorServiceProvider.php:
LivewireDoctor::extend(function ($scanner) {
$scanner->addRule(new class implements LivewireDoctorRule {
public function check(Component $component) {
// Custom logic (e.g., check for deprecated methods)
}
});
});
False Positives
@js directives in Blade files that are dynamically generated (e.g., via JavaScript).config/livewire-doctor.php:
'excluded_paths' => [
'resources/views/vendor/*',
],
Overzealous Fixes
livewire:doctor:fix may overwrite manual changes (e.g., custom property names).php artisan livewire:doctor:fix --dry-run
Performance
php artisan livewire:doctor:scan --path=app/Http/Livewire/Admin
Vite/Laravel Mix Conflicts
@vite directives are misinterpreted if Vite is misconfigured.vite.config.js includes Livewire assets:
export default defineConfig({
build: {
assetsDir: 'assets',
manifest: true,
},
plugins: [
laravel({
input: ['resources/js/app.js', 'resources/css/app.css'],
refresh: true,
}),
],
});
Verbose Output Enable debug mode for detailed logs:
php artisan livewire:doctor:scan --verbose
Custom Log Path
Override the log path in .env:
LIVEWIREDOC_LOG_PATH=storage/logs/livewire-custom.log
Rule-Specific Debugging Isolate rule failures:
php artisan livewire:doctor:scan --rule=assets
php artisan livewire:doctor:scan --rule=properties
Custom Rules
Implement Devrabiul\LivewireDoctor\Contracts\LivewireDoctorRule:
namespace App\Rules;
use Devrabiul\LivewireDoctor\Contracts\LivewireDoctorRule;
use Livewire\Component;
class CustomRule implements LivewireDoctorRule {
public function check(Component $component) {
if ($component->hasMethod('deprecatedMethod')) {
return 'Method `deprecatedMethod` is obsolete. Use `newMethod` instead.';
}
return null;
}
}
Register in LivewireDoctorServiceProvider:
LivewireDoctor::addRule(new \App\Rules\CustomRule());
Post-Scan Hooks Listen to scan events:
LivewireDoctor::listen('scanned', function ($report) {
// Send Slack notification, update database, etc.
});
Fix Customization Override fix logic for specific rules:
LivewireDoctor::extendFixes(function ($fixer) {
$fixer->on('missing_asset', function ($component, $asset) {
// Custom fix logic (e.g., prepend a namespace)
return "@js({...})";
});
});
Excluding Directories
Use glob patterns in config/livewire-doctor.php:
'excluded_paths' => [
'app/Http/Livewire/Tests/*',
'vendor/*',
],
Case Sensitivity
The scanner respects filesystem case sensitivity. On Linux/macOS, ensure component names match exactly (e.g., UserProfile vs userprofile).
Livewire 3 Migration If using Livewire 3, set:
'livewire_version' => '3',
in the config to avoid false positives for v2-specific rules.
How can I help you explore Laravel packages today?