spatie/laravel-blade-comments
Adds HTML debug comments around every rendered Blade view/component so you can see exactly which template produced each piece of output in browser dev tools. Also includes top-level request and view info at the top of the document.
BladeCommenter and RequestCommenter interfaces, enabling team-specific extensions (e.g., adding custom metadata like user context or performance metrics).APP_DEBUG), avoiding runtime overhead in production.@include, @extends, @section, and Livewire components, covering 90%+ of common Blade use cases.@include and @yield directives prevent noise in partials (e.g., CSS/JS includes).enable => env('APP_DEBUG')), so no runtime cost.@include uses complex logic (e.g., {{ $dynamicView }}). Mitigated by the excludes.includes config.laravel-debugbar.RequestCommenter implementations?laravel-view-debugger (more visual) or tighten/laravel-view-debugger (simpler).--dev flag).php artisan vendor:publish --tag="blade-comments-config") and customize:
excludes.includes: Blacklist non-Blade partials (e.g., styles.app).excludes.sections: Exclude @yield in meta tags or attributes.RequestCommenter to add custom headers (e.g., X-Debug-View: dashboard).// app/Commenters/CustomRequestCommenter.php
namespace App\Commenters;
use Spatie\BladeComments\Commenters\RequestCommenters\RequestCommenter;
class CustomRequestCommenter implements RequestCommenter {
public function comment(Request $request): ?string {
return "<!-- Debug: User={$request->user()->id} -->";
}
}
Register in config/blade-comments.php:
'request_commenters' => [
// ... default commenters
App\Commenters\CustomRequestCommenter::class,
],
<!-- /resources/views/layouts/app.blade.php -->) in the team’s debugging guide.Ctrl+F for <!-- /).@include, @extends, @section, @component, and Livewire directives out of the box.laravel-mix, tailwindcss, or inertiajs (comments are HTML-agnostic).spatie/laravel-html for sanitization). Test with htmlspecialchars or similar.Cache::remember) works as usual; comments are injected after caching.--dev, so no impact on production dependencies.resources/views.resources/views/partials/header.blade.php?").APP_DEBUG=false in production.@include), the package skips it and logs a warning.How can I help you explore Laravel packages today?