Print the values on server side in Laravel Php

Sajid Ahmad picture Sajid Ahmad · May 22, 2014 · Viewed 9.6k times · Source

I am totally new to PHP and Laravel Framework.I want to print the variables in Laravel on server side to check what values they contains. How can I do console.log or print the variable values on the server to see what those contains in Laravel PHP.

Answer

msturdy picture msturdy · May 22, 2014

The Shift Exchange's answer will show you the details on the page, but if you wish to log these variables without stopping the processing of the request, you should use the inbuilt Log class:

You can log at various "levels" and when combined with PHP's print_r() function inspect all manner of variables and arrays in a human-readable fashion:

// log one variable at "info" logging level:
Log::info("Logging one variable: " . $variable);

// log an array - don't forget to pass 'true' to print_r():
Log::info("Logging an array: " . print_r($array, true));

The . above between the strings is important, and used to join the strings together into one argument.

By default these will be logged to the file here:

/app/storage/log/laravel.log