Hi! I know this is a very basic question but still im looking for a neat approach when handling uploaded file.. creating a record with file is very easy since you will just directly store the file but how about updating the file with these scenarios:
How to determine that the file has been removed?
How to determine that there are no changes in the uploaded file?
Storage::delete('file.jpg'); // delete method returns a bool, you could use an if statement if file was deleted or not, example
if(Storage::delete('file.jpg')) {
// file.jpg was deleted
// replace it with new file
}
How to determine that there are no changes in the uploaded file?
what do you mean here? with what kind of files are you working?
@Sergiu17 what i mean what should be the logic on how to update uploaded files.. my current logic is that there will be two fields: file field and the file path field, so if file path and file field is null it means i need to remove the file that is associated with the record. If the file path is not null then no changes in the uploaded file, if the file path is null and file field is not then it means i need to replace the uploaded file
// if file path and file field is null it means i need to remove the file that is associated with the record
if(!$request->has('file-path') && !$request->has('file')) {
// remove file
}
// if the file path is null and file field is not then it means i need to replace the uploaded file
else if(!$request->has('file-path') && $request->has('file')) {
// delete the existing file
// save new file
}