0

I am trying to set the page title in Laravel to be the name of the file that is being viewed in the browser. I have looked through the documentation and questions on stack overflow and cannot seem to find the solution. The page title keeps defaulting to the primary key

public function download(SomeModel $document)
{
   if(Storage::disk('s3')->exists($document->file_path)) {
       return \Response::make(Storage::disk('s3')->get($document->file_path), 200, [
           'Content-Type' => 'application/pdf',
           'Content-Disposition' => 'inline; filename="'. $document->custom_file_name .'"'
            ]);
    }
    return view('errors.404');
}

How can I make it to where the <title></title> of the page is using the $document->custom_file_name as opposed to being the id.

Taylor Foster
  • 1,103
  • 1
  • 11
  • 24

1 Answers1

0

You need to set the Title metadata on your pdf document, then the browser will interpret it as the title automatically.

http://www.w3.org/TR/WCAG20-TECHS/PDF18.html

Anton Bks
  • 482
  • 3
  • 10
  • Is there anyway to set this when the file is uploaded to S3, that way the user doesn't have to do this manually? – Taylor Foster Aug 23 '19 at 15:37
  • Personally don't have much experience with S3 but have a look at this, might work: https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html . However I'm not sure how you could set this on upload – Anton Bks Aug 23 '19 at 15:40
  • Actually, on upload I think you can directly post with a metadata param, i.e : `Metadata: { title: 'foobar' }` – Anton Bks Aug 23 '19 at 15:44