44

I'm working on a Laravel application and can debug my controller php files fine, but Id like to also debug the blade.php files. With my current setup Ive followed all of jetbrains recommend settings for Laravel, (https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm#LaravelDevelopmentusingPhpStorm-DebuggingLaravelApplicationswithPhpStorm) but it is still not allowing my to set breakpoints in the blade.php files.

What could I be missing?

9
  • 1
    In what file -- original .blade.php or compiled blade file? You definitely cannot set it in original one -- because it's not executed.
    – LazyOne
    Feb 13, 2015 at 13:50
  • Thanks for the fast response, I didnt know that it was compiled and generated separately. Yes I am referring to the original blade.php file. Whats the best way to debug php variables in the compiled files then?
    – Don F
    Feb 13, 2015 at 13:55
  • 1
    I think PhpStorm has some issues with debugging actual compiled blade files (due to the way how files got named and how IDE works: such files have no extension and IDE is unable to associate them with PHP files file type in order to be able to place breakpoints etc). Please refer to this ticket: youtrack.jetbrains.com/issue/WI-25835
    – LazyOne
    Feb 13, 2015 at 13:58
  • 1
    The blade syntax cannot be evaluated by the debugger (because the interpreter is implemented in Laravel). While PHPStorm does offer support for Blade templating to a certain extent, it cannot place breakpoins inside a blade.php file unless the code is within <?php ... ?>.
    – Bogdan
    Feb 13, 2015 at 13:58
  • 1
    Better look at this one: youtrack.jetbrains.com/issue/WI-26476
    – Kootli
    Feb 13, 2015 at 17:39

5 Answers 5

101

Putting a

<?php xdebug_break(); ?>

into your blade file works pretty well. Even in my tests, PHPstorm jumps to the next PHP statement in some cases.

Why this works:

Laravel processes the blade file to a normal PHP file in the cache folder. But the PHP statement xdebug_break(); will be transferred there and cause the program to halt at the position you want it to (in the cache file).

3
  • 1
    I found this trick works for debugging .thtml files in PHPstorm too. Thanks a lot!
    – TryHarder
    Nov 24, 2016 at 0:15
  • This same trick works in XDebug, using any IDE that supports it. I'm using it with UltraEdit Studio, although it should work in your favorite IDE, even my least favorite, Eclipse. Dec 21, 2017 at 5:12
  • So sweet. Works in Gitpod (THEIA) too! php file with a hash for a name is opened and all the blade logic is converted to php tags. Thank @Alex!!
    – apena
    Jan 21, 2021 at 23:24
10
  1. Go to your Jetbrains IDE Settings (Ctrl+Alt+S; +,; etc.)
  2. Languages & Frameworks > PHP > Debug > Tempates
  3. Enter in Blade Debug > Cache path: \path\to\app\storage\framework\views
  4. Enjoy
1
  • With the Slim Framework I had to point to the Cache files. Aug 31, 2022 at 10:01
3

To close this question - phpstorm doesnt support this functionality at the moment. A work around provided by jetbrains support was to add *.blade.php to file type associations under PHP in the IDE settings, however, it still wasnt working for me after doing this.

It appears that they created a youtrack ticket in response to my request, if youd like to encourage jetbrains to work on this please upvote: youtrack.jetbrains.com/issue/WI-26476

2

Even if you can get the IDE to enable breakpoints on the blade files, it won't work - Laravel composes a PHP file from the Blade file - it is this file that is eventually used when the script is run - not the Blade file.

A Work-Around

This works for PHPStorm - but something similar might be possible in other IDEs.

Laravel (5) stores the composed files under storage/framework/views. These files have random generated file names - so it may be tricky to find the file you want. An easy way is to delete all these temp files and then refresh the page you want to debug. A new file will be created. In PHPstorm you can right-click on the file and select the file's extension type. (Not sure about other IDEs)

You will now be able to set breakpoints. Obviously you will need to make the changes in the Blade file - but this will at least help you to figure out what is wrong.

**Update: Alex's solution is easier! **

1
  • Setting a break point might not be possible because they don't have .php extension. That is why I made a pull request for this: github.com/laravel/framework/pull/10462 - also the cache file name is not random - it is the md5 hash of the view file path.
    – Alex
    Oct 3, 2015 at 14:09
0

I devised an even better hack, which allows conditional debugging support, so that you aren't stuck with XDebug_break for the rest of eternity.

The single line expands as follows.

<?php if ( \app\utils\DebugLogger::EnableForBlades ( ) ) xdebug_break ( ) ; ?>

This statement has a couple of unusual features.

  1. Since blade files done't have use directives, the method name, \app\utils\DebugLogger::EnableForBlades is fully qualified.
  2. Since blade files seem to lack support for the usual code blocking mechanism, the one-line statement is devoid of braces, and is terminated by a semicolon.

EnableForBlades is a static method that queries an environment variable (one of those defined in .local.env), returning True if that variable evaluates to True. Otherwise, it returns False, and xdebug_break is suppressed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.