在 Laravel Php 中打印服务器端的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23806798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:33:13  来源:igfitidea点击:

Print the values on server side in Laravel Php

phplaravellaravel-4laravel-3

提问by Sajid Ahmad

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.logor print the variable values on the server to see what those contains in Laravel PHP.

我对 PHP 和 Laravel Framework 完全陌生。我想在服务器端打印 Laravel 中的变量以检查它们包含的值。如何console.log在服务器上执行或打印变量值以查看 Laravel PHP 中包含的内容。

回答by msturdy

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

Shift Exchange 的回答将在页面上显示详细信息,但如果您希望在不停止处理请求的情况下记录这些变量,则应使用内置Log类:

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:

您可以在各种“级别”上进行日志记录,并在与 PHP 的print_r()函数结合使用时以人类可读的方式检查各种变量和数组:

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

回答by Laurence

The most helpful debugging tool in Laravel is dd(). It is a 'print and die' statement

Laravel 中最有用的调试工具是dd(). 这是一个“打印和死亡”声明

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

What is cool is that you can place as many variables in dd()as you like before dying:

很酷的是,您可以dd()在死前放置任意数量的变量:

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

gives output

给出输出

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