doumian3780 2018-06-03 19:38
浏览 279
已采纳

如何使用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? (PHP's global variables, session data, ...) Because I believe this data can help me a lot to debug.

What I tried:

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

{{ print_r($request) }}

But I get a memory size exhausted error message (even after I changed the limit to 1GB).

So there might be a better way to do this. Maybe also a more readable way.

  • 写回答

1条回答 默认 最新

  • dsaxw4201 2018-06-03 22:40
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料