Things You May Not Know About dd() in Laravel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys today I want to talk about those two letters DD a function which we probably have used at least once in our larel career and there's more to that than just those two letters there are other Alternatives there are laral helpers of DD specific on some classes so let me show you all the variety of DD and side note of course for debugging you may want to use x debug you may want to use external tools like spoty array but I feel that majority of are pretty used to those two letters so first let's see what's inside and this may surprise you if you click in PHP storm you may find out that DD is not actually a laral function if you take a look here vendor Symphony V dumper so DD actually comes from Symphony and not from larl laral actually uses a lot of symphony classes under the hood which makes it a good combination of tools so what's inside that DD two things that may be new to you did you know that DD automatically returns 500 internal server error so you're not just dumping and dying but also tell your browser or your client that it was a 500 error and also second thing did you know you can DD several variables at once so for example I've experimented on my random project it's filament project but that doesn't matter so if you do this or this and refresh and we have three time DD so it dumps all the variables and only then the script dies now if you want to just dump variables in the same Symphony VAR dumper helper above we have dump so you can do dump instead of DD and then if you refresh we have those values above but the script continues and interestingly I'm not sure why maybe it would help me here another difference between dump and DD that dump Returns the value or Returns the last value of of those variables if there were many I'm not sure why would you need that maybe comment below if you know the Practical use case of that so that's one thing I wanted to show you DD from Symphony but then also on top larl adds DD function to many of its classes so if we look for function DD in Vendor laral you may find interesting things like query Builder does the DD and there's more to that there's DD raw SQL and I have a separate video about that which is a pretty recent feature in laravel dumping the query with the bindings and also you may find that carbon has DD so you can do something like user created at DD chained at the end instead of using DD before the variable and a few of those DD helpers are explained in laral documentation so if you look for DD in laral docs for example in collections there is a method that whatever collection you have it may be eloquent collection from database instead of doing DD up front you may chain the DD for example get map with keys filter something something and then DD at the end as part of that chain or another example HTTP client you may do something like this HTTP DDD and then get the URL which would terminate the script execution and dump the request instance again for debugging purposes and of course there's also Benchmark DD which would Benchmark a few of your queries or requests basically any laral or PHP function you have it would measure how much time it takes and would get the results on the screen in milliseconds I also have a separate video about that and I'll link that in the description below and also kind of a side note tip from Al here did you know that you can do DD in Blade not by showing the helper calling the helper but there's a blade directive at DD same thing but a bit shorter and for other use case of DD that I showed in my PHP storm but I didn't dig deeper into that let me leave it to you as a homework so you would not be just passive viewers on this channel and also it's really beneficial to learn to read the source of your tool frame or laral or whatever that is so I hope you're curious enough what dd does for string or innumerable classes in larl and in the comments below you may share your own experience of creative uses of DD maybe with some chain of other methods or on some specific class class just share any of your experience on that topic that's it for this time and see you guys in other videos
Info
Channel: Laravel Daily
Views: 15,127
Rating: undefined out of 5
Keywords:
Id: __aqe3n6YZo
Channel Id: undefined
Length: 4min 35sec (275 seconds)
Published: Sun Oct 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.