Download attachment
downloadAttachment()
Gets executed when a customer downloads a ticket attachment.
Parameters
Type | Name | Description |
|---|---|---|
Ticket | $ticket | The Ticket object of hostware. The $ticket->ticket_provider_external_id contains the external ticket id. |
TicketAttachment | $ticketAttachment | TicketAttachment model containing the ID. |
Response
Download of the file
Example Code
public function downloadAttachment(Ticket $ticket, TicketAttachment $attachment): BinaryFileResponse {
$ticketMessages = $this->getTicketMessages($ticket->ticket_provider_external_id);
/** @var TicketMessageAttachmentResponse $attachmentDetails */
$attachmentDetails = $ticketMessages->pluck('attachments')->flatten()->where('id', $attachment->file_path)->first();
$tempImage = tempnam(sys_get_temp_dir(), $attachment->name);
copy($attachmentDetails->url, $tempImage);
return response()->download($tempImage, $attachment->name);
}Testing
You can test this function by downloading a ticket attachment as a customer.
Was this helpful?