I don't see any validation? But why are you returning null? If the user never uploaded, it just stops everything?
Jun 29, 2022
2
Level 2
Cannot upload/overwrite file in update() method
I have an update method that is supposed to allow a user to upload a file. When I update the fields without the file upload, the request passes a success message. However, when I try a file upload, all the validation errors are fired, despite the form having all the required data.
if ($request->hasFile('file_url')) {
$file = $request->file('file_url');
$name = $file->hashName();
$path = $file->move('zips', $name);
if (Storage::exists($task->file_url)) {
Storage::delete($task->file_url);
} else {
return null;
}
}
$task->update([
'task_name' => $request->task_name,
'due_date' => $request->due_date,
'start_date' => $request->start_date,
'priority' => $request->priority,
'status' => $request->status,
'file_url' => $path ?? '',
]);
I cannot understand what I'm doing wrong.
Please or to participate in this conversation.