I managed to get it to work by replacing the $attachment variable with another. I'm guessing $attachment is reserved and needs a certain set of data. here's the code for anyone else who might be struggling with this:
public array $filePaths;
public function attachments(): array {
$filePaths = [];
if (!empty($this->filePaths) && is_array($this->filePaths)) {
// Loop through each file path and create an Attachment instance
foreach ($this->filePaths as $filePath) {
if (is_string($filePath) && !empty($filePath)) {
$filePaths[] = Attachment::fromPath(storage_path('app/public/' . $filePath));
}
}
}
return $filePaths;
}