deleting attachments when master / sub task is deleted

This commit is contained in:
StudioTem committed 2023-02-14 09:15:04 +01:00
1 parent 17ed7616ee
commit f35cd29071
4 files changed
+59 -3

No files matched your search

+8
View File
@@ -47,4 +47,12 @@ class Attachment extends Model
return $attachmentDataArray;
}
public function deleteFromS3()
{
$path = 'jandl_taskmanager/attachments/' . $this->master_task_id . '/' . $this->disk_name;
Storage::disk('s3')->delete($path);
return true;
}
}
+11
View File
@@ -53,4 +53,15 @@ class MasterTask extends Model
// return random value from array
return collect(['#E9FFE5', '#F6ECD3', '#FDE1FF', '#FFC9C9', '#DADEF8', '#EDFFFE'])->random();
}
public function deleteAttachments()
{
foreach ( $this->attachments as $attachment ) {
$attachment->deleteFromS3();
}
$this->attachments()->delete();
return true;
}
}