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