Hello guys... 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?
$path = $request->file('gambar')->store('gambarpekerjaan');
// $path will be a file name with a random hash
Also, you really want to look into validation, because right now you’re not doing anything and blindly passing anything the user submits to your model for saving, which is a huge security risk if you model has many fillable or un-guarded attributes.
You also have a bug where you’re not checking if the model exists before calling methods on it. This line:
$pekerjaan = Pekerjaan::find($id);
Is going to cause a crash if a user specifies the ID of a model that doesn’t exist, because $pekerjaan is going to be null but then you try and call update on it, so you’re going to end up with a “Trying to call method on null” error.