title: How to give uniqid/hash value to saved file in Laravel
body: <p>I have a function that let a user to upload and save the file to the system and show the file in the table. The problem is whenever there is a duplicate name it will not appear in the database and the file will not show in the table. As the title says, how to give uniqid/hash value to saved file?</p>
  <p>Here is my code:</p>
  <pre><code>public function updatepekerjaan(Request $request, $id){
          $pekerjaan = Pekerjaan::find($id);
          $pekerjaan-&gt;update($request-&gt;all());
          if($request-&gt;hasFile('gambar')){
              $request-&gt;file('gambar')-&gt;move('gambarpekerjaan/', $request-&gt;file('gambar')-&gt;getClientOriginalName());
              $pekerjaan-&gt;gambar = $request-&gt;file('gambar')-&gt;getClientOriginalName();
              $pekerjaan-&gt;save();
  
  
              // $file = request()-&gt;file('gambar');
              // $extension = $file-&gt;getClientOriginalName();
              // $destination = 'gambarpekerjaan/';
              // $filename = uniqid() . '.' . $extension;
              // $file-&gt;move($destination, $filename);
              // $new_file = new Pekerjaan();
              // $new_file-&gt;gambar = $filename;
              // $new_file-&gt;save(); &lt;&lt; doesn't work
          }
          
          return redirect()-&gt;route('datapekerjaan')-&gt;with('message','Pekerjaan Berhasil diupdate!');
      }
  </code></pre>
  <p>I have also tried changing the <em>getClientOriginalName</em> into <em>hashName</em> but it doesn't work</p>
  <pre><code>$pekerjaan-&gt;update($request-&gt;all());
          if($request-&gt;hasFile('gambar')){
              $request-&gt;file('gambar')-&gt;move('gambarpekerjaan/', $request-&gt;file('gambar')-&gt;hashName());
              $pekerjaan-&gt;gambar = $request-&gt;file('gambar')-&gt;hashName();
              $pekerjaan-&gt;save();
  </code></pre>