title: Laravel deleting old image after updating
body: <p>I want my user's old image to be deleted when they update it. This current function does not work how I want it. How would I change it so it works?</p>
  <pre><code> public function update($id)
          {
              $profile = Profile::findOrFail($id);
      
              $data = request()-&gt;validate([
                  'title' =&gt; 'required|max:255',
                  'image' =&gt; ''
              ]);
      
              if ($profile-&gt;image) {
                  if (Storage::exists(&quot;storage/{$profile-&gt;image}&quot;)) {
                  Storage::delete(&quot;storage/{$profile-&gt;image}&quot;);
                }
  }
                  
              if (request('image')) {
                  $imagePath = request('image')-&gt;store('profile', 'public');
                  $image = Image::make(public_path(&quot;storage/{$imagePath}&quot;))-&gt;orientate()-&gt;fit(1000, 1000); //Intervention Image Package
                  $imageArray = ['image' =&gt; $imagePath];
                  $image-&gt;save();
              }
          
      
              
              // $profile-&gt;image = $request-&gt;image; //Lägg till senare
              
              $profile-&gt;update(array_merge(
                  $data,
                  $imageArray ?? [],
              ));
      
      
      
              return redirect(&quot;/profile/{$profile-&gt;user_id}&quot;);
          }
      }
  </code></pre>