Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

screwtape_mk's avatar

Dynamic og meta tags for facebook preview post

Hi

The image preview of my facebook posts from my laravel web application do not work. I have been advised atleast by the facebook debug tool to explicitly specify the og meta tags. This however needs to be defined dynamically and not hardcoded.

This is what i have:

<meta property="og:image" content="{{Storage::url('app/public/property/'.$property->image)}}"/>

However i get the following error according to the facebook debug tool:

Provided og:image URL, /storage/app/public/property/ was not a valid URL

Please assist with the right syntax for this

0 likes
4 replies
webrobert's avatar

@screwtape_mk

you shouldn't need to specify a path app/public/property/ here...

<meta property="og:image" content="{{ Storage::url($property->image) }}"/>

When using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.

https://laravel.com/docs/9.x/filesystem#file-urls

screwtape_mk's avatar

@webrobert can you elaborate further on how to do this, should i be specifying in the header the og:url meta tag? and if so what should it be?

screwtape_mk's avatar
screwtape_mk
OP
Best Answer
Level 2

@webrobert i ended up applying the following snippet of code in the main view for which i wanted a post preview:

@section('meta-tags')

 @php
 $firstImage = $property->gallery->first();
 @endphp
 @if($firstImage)
<meta property="og:image" content="{{ Storage::url('app/public/property/gallery/'.$firstImage->name) }}" />  
 @else
 <meta property="og:image" content="{{ asset('frontend/images/placeholder/placeholder-property-single-image.jpg') }}" />  
 @endif

@endsection

because the images are in a slider and wanted to just grab the first image as a preview image.

Please or to participate in this conversation.