Search code examples
phphtmlfacebooklaravelmeta-tags

Adding Header to a Laravel view


im trying to share an image url on facebook , and for a preview to appear on facebook , i need to include the meta tags , "og:title", "og:type", "og:image" ,"og:url" ,and this works perfectly if i return a view ('image' , $imagename); but then its displayed within an image tag.

i want to be Displayed as it would when u make the header as content-type:image/jpeg

i tried the following :

  • return response ()->file ( $imgPath , [ 'image/jpeg' ] ); which does the job , but im not refering my view here , so meta tags arent rendred..
  • return response ()->view ( 'image' , [ 'imgPame' => $imgPath ] )->header ( 'Content-Type' , 'image/jpeg' ); this does it aswell but it displays an error that the image isnt found , and when i inspect it with chrome tools , i dont see the meta tags as well ..

how can i do that? , when i share a google image facebook reads its meta tags normally but wont on my url .. so no preview is displayed


Solution

  • This was solved by adding a domain to my website , return response ()->file ( $imgPath , [ 'image/jpeg' ] ); with the domain did the job.