Last active
October 12, 2020 10:52
-
-
Save victorloux/0c073afa5d4784d2b8e9 to your computer and use it in GitHub Desktop.
@Dump directive for Blade in Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// place the following in app/Providers/AppServiceProviders.php, in the boot() method | |
/** | |
* Blade directive to dump a variable/object inside a template. | |
* This is similar to dd(), except that it doesn't interrupt the | |
* execution of the app. It does NOT support multiple arguments | |
* however, you have to use one directive per variable. | |
* | |
* @example @dump($posts->comments) | |
*/ | |
Blade::directive('dump', function($param) { | |
return "<pre><?php (new \Illuminate\Support\Debug\Dumper)->dump{$param}; ?></pre>"; | |
}); |
@imabug no, because {$param}
gets changed to ($posts->comments)
including the parentheses, so otherwise it'd compile to ->dump(($posts->comments))
and that caused issues iirc
(but that gist is from 2 years ago so the Laravel API might have changed, I need to test it again)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be
dump($param)
instead ofdump{$param}
?