Home > other >  Save POST data to exception context in Laravel
Save POST data to exception context in Laravel

Time:10-22

So I'm adding some data to my exceptions that get logged in my Laravel 9 application by overriding the context() method in app/Exceptions/Handler.php.

I tried to add POST data by doing the following:

if (!empty($_POST)) {
    $context['post'] = $_POST;
}

But this does not work because $_POST is always empty. If I had access to the $request I could get it from there, but I can't access it from here as far as I can tell.

I wasn't aware that post data wasn't saved in $_POST like I would have expected in Laravel. Is there any way to access this data to include it in the exception?

CodePudding user response:

How about the \request() helper method?

    if (count($post = \request()->post())) {
        $context['post'] = $post;
    }
  • Related