title: How to Validate File Upload in Laravel
body: <p>I've completed a <a href="https://laraveldaily.com/upload-multiple-files-laravel-5-4/" rel="nofollow noreferrer">tutorial</a> to upload image files. How can I validate file uploads in the view when a user uploads a file larger than 2MB?</p>
  
  <p><strong>create.blade.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>@if (count($errors) &gt; 0)
      &lt;div class="alert alert-danger"&gt;
          &lt;strong&gt;Whoops!&lt;/strong&gt; Errors.&lt;br&gt;&lt;br&gt;
          &lt;ul&gt;
              @foreach ($errors-&gt;all() as $error)
                  &lt;li&gt;{{ $error }}&lt;/li&gt;
              @endforeach
          &lt;/ul&gt;
      &lt;/div&gt;
  @endif
  @if(session('success'))
      &lt;div class="alert alert-success"&gt;
          {{ session('success') }}
      &lt;/div&gt;
  @endif
  &lt;div class="form-group"&gt;
      &lt;input type="file" name="photos[]" multiple aria-describedby="fileHelp"/&gt;
      &lt;small id="fileHelp" class="form-text text-muted"&gt;jpeg, png, bmp - 2MB.&lt;/small&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Rules</strong></p>
  
  <p>
  
  <pre><code>public function rules()
  {
      $rules = [
          'header' =&gt; 'required|max:255',
          'description' =&gt; 'required',
          'date' =&gt; 'required',
      ];
      $photos = $this-&gt;input('photos');
      foreach (range(0, $photos) as $index) {
          $rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
      }
  
      return $rules;
  }
  </code></pre>
  
  <p>Everything is ok, however when I try to upload a file which is larger than 2MB it gives me an error:</p>
  
  <blockquote>
    <p>Illuminate \ Http \ Exceptions \ PostTooLargeException No message</p>
  </blockquote>
  
  <p>How can I solve this and secure this exception?</p>