Laravel 5: Handle exceptions when request wants JSON

前端 未结 8 1712
野的像风
野的像风 2021-01-30 05:30

I\'m doing file uploads via AJAX on Laravel 5. I\'ve got pretty much everything working except one thing.

When I try to upload a file that is too big (Bigger than

8条回答
  •  情深已故
    2021-01-30 05:58

    My way:

    
        // App\Exceptions\Handler.php
        public function render($request, Throwable $e) {
            if($request->is('api/*')) {
                // Setting Accept header to 'application/json', the parent::render
                // automatically transform your request to json format.
                $request->headers->set('Accept', 'application/json');
            }
            return parent::render($request, $e);
        }
    

提交回复
热议问题