Nono.MA

Log Laravel request parameters

NOVEMBER 18, 2022

Here's a way to encode a Laravel site request as JSON to log it via Laravel's logging mechanism, using the Log class from the illuminate/support package1.

// Log parameters in a get request
Route::get('a-view', function(Request $request) {
  \Log::info(json_encode(request()->server()));
  return view('your.view');
});

// Log parameters in a get request and redirect
Route::get('redirect', function(Request $request) {
  \Log::info(json_encode(request()->server()));
  return redirect('/some/page');
});

  1. The service provider of Laravel's Log class is Illuminate\Support\Facades\Log

BlogCodePhpLaravel