在我的ReportController.php
中,我的函数收到Request $request
,如下所示:
class ReportController extends Controller{
public function store(Request $request)
{
\Log::info("Request content:");
\Log::info($request);
error_log("request:");
error_log($request);
$insertID = Report::create([
'action' => $request->action,
'reportID' => $request->reportID,
'incidentDate' => $request->incidentDate,
'who' => $request->who,
'location' => $request->location,
'description' => $request->details,
'submittedByName' => $request->submittedByName,
'submittedByMobile' => $request->submittedByMobile,
'submittedByEmail' => $request->submittedByEmail,
'attachments' => $attachments,
'attachmentCount' => $attachmentCount,
'request' => $request
])->id;
}
}
奇怪的是,$request
的值随我转储它们的位置而变化。例如,在我使用\Log::info($request)
登录的日志文件中,该文件显示为:
[2019-05-28 17:35:27] local.INFO: array (
'action' => 'TellUsMore',
'reportID' => 'b19xr211gcbvc',
'incidentDate' => '2019-05-29',
'location' => 'ggg',
'description' => 'gg',
'suggestion' => 'sdfsdf',
'files' =>
array (
0 =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'reports (1).xlsx',
'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'error' => 0,
'hashName' => NULL,
)),
1 =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'love your parents - we\'re so busy growing up, we often forget that they\'re growing old.jpg',
'mimeType' => 'image/jpeg',
'error' => 0,
'hashName' => NULL,
)),
),
)
但是在我的error_log($request)
中,它会在控制台中转储值,它会显示
[Wed May 29 01:35:27 2019] POST /api/report/store HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 25172
Content-Type: multipart/form-data; boundary=--------------------------416520203821764707296428
Host: localhost:8000
Postman-Token: 76adb08d-631e-4f10-9a5f-60bc8d015aed
User-Agent: PostmanRuntime/7.6.0
当我将$request
值存储在数据库中时,情况相同。我本来打算将正在显示的$request
值存储在我的laravel日志文件中,但是却将$request
的值保存为在控制台中显示的值。
我在这里想念什么?
答案 0 :(得分:2)
error_log()
调用$request->__toString()
,您的Log类出于某些原因调用var_export()
。就是这样;)