title: Laravel - Convert a base64 string to a valid image
body: <p>To give you a grasp of what I am trying to do, here is my current code</p>
  
  <p><em>This code is run when a post request is made to specific URL</em></p>
  
  <pre><code>public function uploadImage(Request $request) {
      $request-&gt;file = base64_decode(explode(',', $request-&gt;file)[1]);
  
      $request-&gt;validate([
          'file' =&gt; 'image|required|mimes:jpg,png',
      ]);
  
      $image = $request-&gt;file('file');
  
      $complete = $image-&gt;getClientOriginalName();
      $name = pathinfo($complete, PATHINFO_FILENAME);
      $extension = $image-&gt;getClientOriginalExtension();
      $storageName = $name.'_'.time().'.'.$extension;
  
      Storage::disk('public')-&gt;put($storageName, File::get($image));
  
      return Storage::disk('public')-&gt;path($storageName);
  }
  </code></pre>
  
  <p>On the first line I am trying to be smart and first decode the base64 to a file (if I am correct?).</p>
  
  <p>Next is a validation to validate if the <code>file</code> parameter in the request exists, is an image, and is a <code>.jpg</code> or <code>.png</code></p>
  
  <p>(The next lines is just about saving the "image" to the filesystem)</p>
  
  <p>But the validation won't pass because the <code>file</code> parameter is not an image. So my question is: is it possible to convert a base64 string to a valid image in Laravel? If it is, how can this be achieved?</p>