September 20, 2014 —John Koster
So, a while ago I wrote this post about working with Laravel and Kint. It works, but it can be a pain to manage through composer updates (losing your lock file, whatever happens), Laravel upgrades, it doesn't matter. The problem is that sometimes using the dd()
function doesn't always display the really nice Kint table breakdown when using it with Laravel. Let's fix that once and for all!
Since we are trying to get everything to work nicely with Kint, we should probably have Kint required in our project. Add this to your composer.json
file (either in your require
or require-dev
section. I put mine in the require-dev
section):
1...2"raveren/kint": "0.9.*",3...
Looking through the issue some more today, I decided to write a new modify one of Kint's functions to work really nice with Laravel. Add this function to some helpers file, or a file that is accessed throughout your application:
1if (!function_exists('lk')) 2{ 3 /** 4 * Dump information about variables that Laravel will like. 5 * 6 * @param mixed $data 7 * 8 * @return void|string 9 */10 function lk()11 {12 if ( !Kint::enabled() ) return null;13 14 $args = func_get_args();15 call_user_func_array( array( 'Kint', 'dump' ), $args );16 die;17 }18}
This is almost the same function as Kint's d()
function, except that I've omitted the return
statement. It doesn't seem to work every time with the return line in. We can use the new lk()
(Laravel Kint) function just like we used the dd()
function:
1lk(Input::all());
There we go! A little function (lk()
) that I can use without fuss to get the niceness of Kint when using Laravel. Not a complicated solution, but those are the best.
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.