title: Saving image path to database using Laravel
body: <p>I have a function that takes submitted form data which is an image, then validates it and it deletes an old image if one already exists. It currently does that and stores the image on in the storage folder. </p>
  
  <p>I am now trying to save the URL of the image to the database. I have seen examples where they do not save the path to the database but would it be best to do so?</p>
  
  <p>Here is my function</p>
  
  <pre><code>public function postAvatarUpload(Request $request)
      {
           $this-&gt;validate($request, [
              'image' =&gt; 'required|image|max:3000|mimes:jpeg,jpg,bmp,png',
          ]);
          $user = Auth::user();
          $usersname = $user-&gt;username;
          $file = $request-&gt;file('image');
          $filename = $usersname . '.jpg';
          if (Storage::disk('local')-&gt;has($filename)) {
              Storage::delete($filename);
          }
             Storage::disk('local')-&gt;put($filename, File::get($file));
             $avatarPath = Storage::url($filename);
              Auth::user()-&gt;update([
                  'image' =&gt; $avatarPath,
              ]);
  
          return redirect()-&gt;route('profile.index', 
                  ['username' =&gt; Auth::user()-&gt;username]);
      }
  </code></pre>