Skip to content

Instantly share code, notes, and snippets.

@hakobyansen
Last active April 25, 2019 15:18
Show Gist options
  • Select an option

  • Save hakobyansen/cb6e000ab130f64ab676aee45d3ba92a to your computer and use it in GitHub Desktop.

Select an option

Save hakobyansen/cb6e000ab130f64ab676aee45d3ba92a to your computer and use it in GitHub Desktop.
Even if you have file size validation implemented, you will get PostTooLargeException if you're trying to upload file larger than size specified in your php.ini config file. This gist shows how you can handle PostTooLargeException in Laravel.
<?php
// App\Exceptions\Handler::render()
public function render($request, Exception $exception)
{
if ($exception instanceof PostTooLargeException)
{
// todo: return response or do whatever you need to do
return response()->json(['message' => 'File is too large.'], 422);
}
return parent::render($request, $exception);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment