When working with Laravel Blade templates there are lots of times when you may want to comment out certain sections of your code, and there are two primary ways of doing this…
Blade Comments
The first way is through Blade itself. You can use the following tag pair as a comment:
{{-- This comment will not be present in the rendered HTML --}}
Under the hood this will compile into something like this:
<?php // This comment will not be present in the rendered HTML ?>
Because it’s a PHP comment the part you comment will not be visible in the source code when someone is viewing it through the browser.
HTML Comments
The second way is by using normal HTML comments:
<!-- This is a comment -->
The difference is this comment will be visible if someone views the source code of you page in the browser.
As a general rule of thumb, you should always go with the Blade style.
Eric is the creator of Laravel News and has been covering Laravel since 2012.