Requirements
Dynamic OG Images based onspatie/browsershot
package and puppeteer
package. You need to install these packages first.
(You can skip this step if you already installed these packages, packages included in Larafast by default)
Check the official Spatie docs for requirements: https://spatie.be/docs/browsershot/v4/requirements
Configuration
Modify theresources/views/seo/image.blade.php
file to create your own dynamic OG Image template.
Usage
To have your og image generated dynamically, you need to use following route:your-title.jpg
file name. If the file already exists, it will not generate a new image.
Example
@include('seo')
in your layout file, you can use the following inside controllers:
Dynamic OG image can be used also as an article images, just use the same route instead of image icon
If you need to reset your open graph images cache in Twitter use https://cards-dev.twitter.com/validator or add ?v1=true after your url for which you want to reset it
Digging deeper
The first load of dynamic og image will be slow, as it will be generated on the fly. After that, generated image will be picked instead of creating new one.Articles or other models with image
For every new article that you create or update, og image will be generated automatically. The logic handled inapp/Observers/ArticleObserver.php
file.
If you have existing articles, or if you modified the template and want to regenerated model og images, you can use the following command:
If you have other models with images, you can create your own observer and use the same logic to generate og images for them.
Make sure to update the
generate:og-images
command to include your models.