[英]How to add request data to support email using Illuminate\Http\Request;
I created a "Ask for support" contact form (using a modal) in my app. 我在应用程序中创建了一个“寻求支持”联系表格(使用模式)。 What would be the best/cleanest way to add/attach a dump of the $request
variable? 添加/附加$request
变量转储的最佳/最干净方法是什么? (PHP's global variables, session data, ...) Because I believe this data can help me a lot to debug. (PHP的全局变量,会话数据等),因为我相信这些数据可以帮助我进行很多调试。
What I tried: 我试过的
SupportController: SupportController:
public function send(Request $request)
{
Mail::send('emails.support', ['request' => $request], function ($message) use ($request) {
$message->from($request->user()->email, $request->user()->name);
$message->subject(trans('Support request'));
});
$request->session()->flash('flash_message', __('Message sent!'));
return redirect()->back();
}
emails.support.blade emails.support.blade
{{ print_r($request) }}
But I get a memory size exhausted error message (even after I changed the limit to 1GB). 但是我收到了内存容量耗尽的错误消息(即使将限制更改为1GB之后)。
So there might be a better way to do this. 因此,可能会有更好的方法来执行此操作。 Maybe also a more readable way. 也许也是一种更具可读性的方式。
Don't dump the entire request object, instead pick and choose what you find necessary to be helpful for debugging. 不要转储整个请求对象,而是选择所需的内容以帮助调试。 For example: 例如:
All:
@foreach($request->all() as $key => $val)
{{ $key }} = {{ $val }}
@endforeach
<hr>
Route Name: {{ $request->route()->getName() }}
Route Action: {{ $request->route()->getAction() }}
Route Method: {{ $request->route()->getMethod() }}
<hr>
Headers:
@foreach($request->headers->all() as $key => $val)
{{ $key }} = {{ $val }}
@endforeach
Etc, etc.. 等等
Or you can use Guzzle's str method to serialize a request or response object. 或者,您可以使用Guzzle的str方法来序列化请求或响应对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.