Print server-side values ​​in Laravel Php

I am completely new to PHP and the Laravel Framework. I want to print the variables in Laravel on the server side to check what values ​​they contain. How can I do console.log or print the values ​​of variables on the server to find out what they contain in Laravel PHP.

+7
php laravel laravel-3 laravel-4
source share
2 answers

The Shift Exchange answer will show you the details on the page, but if you want to register these variables without stopping the processing of the request, you should use the built-in Log class:

You can register at different levels " and in combination with PHP print_r() checks all kinds of variables and arrays using readability:

 // 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)); 

Value . The above between lines is important and is used to combine lines into a single argument.

By default, they will be written to the file here:

 /app/storage/log/laravel.log 
+10
source share

The most useful debugging tool in Laravel is dd() . This statement is "seal and death"

  $x = 5; dd($x); // gives output "int 5" 

What's cool is that you can put as many variables in dd() as you want before you die:

  $x = 5; $y = 10; $z = array(4,6,6); dd($x, $y, $z); 

outputs a conclusion

  int 5 int 10 array (size=3) 0 => int 4 1 => int 6 2 => int 6 
+6
source share

All Articles