user = $user; } /** * @param Attachment $attachment * * @return bool */ public function destroy(Attachment $attachment): bool { /** @var AttachmentHelperInterface $helper */ $helper = app(AttachmentHelperInterface::class); $file = $helper->getAttachmentLocation($attachment); unlink($file); $attachment->delete(); return true; } /** * @return Collection */ public function get(): Collection { return $this->user->attachments()->get(); } /** * @param Carbon $start * @param Carbon $end * * @return Collection */ public function getBetween(Carbon $start, Carbon $end): Collection { $query = $this->user ->attachments() ->leftJoin('transaction_journals', 'attachments.attachable_id', '=', 'transaction_journals.id') ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) ->get(['attachments.*']); return $query; } /** * @param Attachment $attachment * @param array $data * * @return Attachment */ public function update(Attachment $attachment, array $data): Attachment { $attachment->title = $data['title']; $attachment->description = $data['description']; $attachment->notes = $data['notes']; $attachment->save(); return $attachment; } }