Could you point the equivalent command(s)/ function(s) to print_r()  or vardump () when using Laravel?

Eduardo Fuerte
Eduardo Fuerte used Ask the Experts™
on
Hi Experts!

Could you point the equivalent command(s)/ function(s) to print_r()  or vardump () when using Laravel?

As I saw Laravel mantains its own dashboard where informations could be obtained by it, my attempts to use F12  looks that doesn't succeed also.... is it unabled?

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
The functions print_r() + vardump() are PHP, so work with any PHP code.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Laravel is a PHP framework - it is 100% based on PHP so any PHP function you want to use is available.

Laravel does have the dd() (dump and die) but this may not be what you are looking for in all cases so you would use either the PHP functions (print_r, var_dump) or dd depending on what it is you want to achieve.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Hi

So debug by using that functions remains a valid way on Laravel, isn't it?

I just start using Laravel and it seens print_r and var_dump is someway "intercepted" by it's dashboard and the response are not displayed (or is it displayed inside the dashboard?)
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
You can also try doing logging to a file

file_put_contents('debug.log', print_r($variable, true), FILE_APPEND);

Open in new window


and it seens print_r and var_dump is someway "intercepted"

Try putting a die() statement after the dump.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Hi

The way the log file is configured at the app is:
img001
The way I tryed to save at this log file is:
img002
Unfortunatelly no informations are saved at the log file, what else is needed?

And:
By using var_dump inside Laravel code I had to use die also (like you suggested), otherwise I couldn't find a way to obtain the result.
Most Valuable Expert 2017
Distinguished Expert 2018
Firstly I would not use Laravel's log file - you are doing custom debugging so use a different file name.

Secondly - if nothing is appearing in the log then the code is not firing.

I would try with your custom log file first and see if that works.

If it does not then you need to look at why that controller index is not being called
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Unfortunatelly laravel.log is not my choice, a team is using this, but I can suggest them to change its name.

The code is been fired, since I change the code to:
img003
This exception is fired (evidence)
img004
Most Valuable Expert 2017
Distinguished Expert 2018
Unfortunatelly laravel.log is not my choice, a team is using this, but I can suggest them to change its name.
What I am saying is do this
file_put_conents('YOUR_UNOQUE_NON_LARAVAL_LOG_HERE', print_r($variable, true), FILE_APPEND);

Open in new window


The error above is probably because of the '\' in the front of the path - it is trying to find the absolute path \logs\... instead of the relative path. Remove the leading '\'.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
I just forced the error by using this  "\log\" just to evidence the controller index is called.

I guess to follow your suggestion I have to configure \config\logging.php  to make Laravel to use my own log file, isn't it?
Most Valuable Expert 2017
Distinguished Expert 2018
I guess to follow your suggestion I have to configure \config\logging.php  to make Laravel to use my own log file, isn't it?
No, why?

file_put_contents() is a PHP function - it simply writes the provided text to the specified file - it has nothing to do with laravel.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Yes.
I just use the debug.log on this function. That runs.

Just one detail:

$variable='ZZZ'.PHP_EOL;

file_put_contents('debug.log', $variable, FILE_APPEND);

Open in new window


I did a little change on the command to get a new line at every use.
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Thank you for the guidance!
Most Valuable Expert 2017
Distinguished Expert 2018
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial