3

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.

Izati
  • 51
  • 1
  • 3
  • 9
    You 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
  • 2
    Hi, 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
  • You can use core PHP function echo() or print_r() for more see: https://stackoverflow.com/a/73430068/7186739 – Billu Aug 20 '22 at 20:52
  • https://stackoverflow.com/a/73430068/7186739 – Billu Aug 20 '22 at 20:52

3 Answers3

6

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
  • 22,380
  • 8
  • 50
  • 63
  • 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
5

You can use dump as stated on the comment, but there's another way of logging that already wrapped as laravel class here, if you want to debug you can use one of the variant from there Log::debug('An informational message.');

adnntfr
  • 102
  • 4
1

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

Kevin
  • 1,152
  • 5
  • 13