/** * Add a new public message, public message file(s), and a public contact. * * @param Ticket $ticket * @param PublicMessageRequest $request * @param PublicContactRequest $contactRequest * @return PublicMessage */ public function addNewPublicMessage(Ticket $ticket, PublicMessageRequest $request, PublicContactRequest $contactRequest) { // if a file was posted $publicMessageFile = new PublicMessageFile(); if ($request->file('file')) { // save the file into storage and update the eloquent model Event::fire(new PublicMessageFileWasUploaded($request->file('file'), $publicMessageFile)); } // add a new public message $message = new PublicMessage($request->all()); $ticket->publicMessages()->save($message); // add new file to public message if ($publicMessageFile->toArray()) { $message->files()->save($publicMessageFile); } // add a new public contact $this->addNewPublicContact($ticket, $request, $contactRequest); Session::flash('new_public_message_id', $message->id); return $message; }
/** * Display the specified resource. * * @param int $filename * @return Response */ public function show($filename) { $publicMessageFile = PublicMessageFile::whereFilename($filename)->firstOrFail(); $file = Storage::get($publicMessageFile->filepath); $headers = array(); $headers['Content-type'] = $publicMessageFile->mime; // force the file to download if its not an image if (!$publicMessageFile->isImage()) { $headers['Content-Disposition'] = 'attachment; filename="' . $publicMessageFile->filename . '"'; } return response($file, 200, $headers); }