I'm building a website with laravel, i want to debug my program but it's hard to use dd() since it will immediately stop the program, i want to make it show line by line per execution, any idea? any help will be appreciated, thanks.
Asked
Active
Viewed 1,267 times
0
-
8You can use [`dump`](https://laravel.com/docs/8.x/helpers#method-dump). The function `dd` is a wrapper around "dump and die" – Chris Haas Jul 07 '21 at 13:43
-
2Hi, use XDEBUG for profiling and so on – Alex Black Jul 07 '21 at 13:45
-
If you want breakpoints, then XDebug is the way to go. `dd()` is useful, but inherently stops execution, "dump and **die**". You can also use `Log::info()` statements to log stuff as your code executes. – Tim Lewis Jul 07 '21 at 13:48
3 Answers
5
Another way to get your result without outputting to the page (useful for production at times) is to log it to a file. Laravel has Monolog built in, so use
Log::info($data);
and it will write the result to a file in storage/logs within your project folder.
aynber
- 20,647
- 8
- 49
- 57
-
This solution also has the benefit that changes to the session are not reversed. This happens if you are debugging using dd(); – Aless55 Jul 07 '21 at 13:55
-2
As others stated: dd means dump & die. So it dumps the result and stops the excecution.
There is a shorter alternative which is dump and it doesn't kill the excecution.
Could also use print_r
work service
- 619
- 2
- 11