$methods = PaymentMethod::all(); dd($methods);We would see something like this: Oh, ok, three rows. Now what are the values? We have to click to expand it - ok, let's do that: Mmm, now we know which type we are dealing with - "PaymentMethod". [sarcasm]really helpful...[/sarcasm] Let's expand one of the rows now - maybe we will finally see the values? Nope. The final step is to expand attributes or original sections. But you get the point - to see the actual values, we need to click three additional times, and we don't see the full result without those actions. At first I thought - maybe dd() function has some parameters for it? Unfortunately not. So let's look at other options:
var_dump() and die()
Good old PHP way of showing the data of any type:$methods = PaymentMethod::all(); var_dump($methods); die();What we see now: Not easily readable, is it? The trick here is to View Source in browser, in case of Chrome/Windows it's CTRL+U: Better, huh? But there's even more readable way.
Have you tried our tool to generate Laravel adminpanel without a line of code?
Go to QuickAdminPanel.com
print_r()
Another PHP built-in function print_r() has a perfect description for us: "Prints human-readable information about a variable" So if we do this:$methods = PaymentMethod::all(); print_r($methods); die();And then go to View Source of the browser... We get this: Now we can read the contents easily and try to investigate the error. Moreover, print_r() function has another optional parameter with true/false values - you can not only echo the variable, but return it as string into another variable. Then you can combine several variables into one and maybe log it somewhere, for example. So, in cases like this, dd() is not that convenient - PHP native functions to the rescue. But if you want the script to literally "dump one simple variable and die" - then dd($var) is probably the fastest to type.
No comments or questions yet...