百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-blade-comments

> 后端框架
开源

在渲染输出中添加调试注释

180 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

在渲染输出中添加调试注释

Add debug comments to your rendered output

When looking at the HTML of a rendered page, it might not be obvious to you anymore which Blade view is responsible for which HTML. This package will add HTML before and after each rendered view, so you immediately know to which Blade view / component to go to change the output.

When you inspect a part of the page using your favourite browser's dev tools, you'll immediately see which Blade view rendered that particular piece of content. Here's a demo where we inspected the breadcrumbs on our own company site. It is immediately clear that the breadcrumbs are rendered by the front.pages.docs.partials.breadcrumbs Blade view.

At the top of the HTML document, we'll also add some extra information about the topmost Blade view and the request.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

bash
composer require spatie/laravel-blade-comments --dev

You can optionally publish the config file with:

bash
php artisan vendor:publish --tag="blade-comments-config"

This is the content of the published config file:

…

Usage

After the package is installed, you'll immediately see that HTML comments are injected at the start and end of every Blade view.

Excluding views

Sometimes you might not want to have an HTML comment being wrapped around an include. For example when you use a partial to add some CSS to a page. In these cases you can add views to the excludes.includes array in the config file.

Excluding sections

Sometimes you might not want HTML comments wrapping around @yield directives. For example when they're used within HTML attributes or meta tags. In these cases you can add sections to the excludes.sections array in the config file.

Using your own Blade Commenters

You can easily extend the package to add more comments. In the blade_commenters key of the blade_commenters config file, you can add your own BladeCommenter. A BladeCommenter is any class that implements the following interface:

php
namespace Spatie\BladeComments\Commenters\BladeCommenters;

interface BladeCommenter
{
    /*
     * Should return a regex pattern that will be used
     * in preg_replace. 
     */
    public function pattern(): string;

    /*
     * Should return a replacement string that will be
     * used in preg_replace.
     */
    public function replacement(): string;
}

Take a look at the BladeCommenters that ship with the package for an example.

Using your own request commenters

The package adds useful information about the request at the top of the HTML page. This is done by the so called request commenters . You'll find the default request commenters in the request_commenters key of the blade-comments config file.

You can add your own request commenters there. A RequestCommentor is any class that implements the following interface:

php
namespace Spatie\BladeComments\Commenters\RequestCommenters;

use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

interface RequestCommenter
{
    public function comment(Request $request, Response $response): ?string;
}

If the comment function returns a string, it will be injected at the top of the HTML document. Take a look at the request commenters that ship with the package for an example.

Testing

bash
composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

  • Tim Van Dijck
  • Freek Van der Herten
  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPbladedevelopmentlaravel

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架