Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Og Image Laravel Package

spatie/laravel-og-image

Generate Open Graph images in Laravel from Blade-defined HTML. Automatically renders screenshots, serves them from a route, and caches files. Templates reuse your app’s CSS, fonts, and Vite assets—no external API required.

View on GitHub
Deep Wiki
Context7

title: Customizing the page URL weight: 3

When the package caches which URL to screenshot for an OG image, it uses the request URL without query parameters by default. This means /posts?page=2 and /posts?page=3 would both resolve to /posts for the screenshot.

For most pages this is the right behavior, since query parameters like pagination don't affect the OG image. But if your OG image content varies based on query parameters, you can customize how the URL is resolved.

Changing the URL resolution

In your AppServiceProvider, register a closure that receives the current request and returns the URL to use:

use Illuminate\Http\Request;
use Spatie\OgImage\Facades\OgImage;

public function boot(): void
{
    OgImage::resolveScreenshotUrlUsing(function (Request $request) {
        return $request->fullUrl();
    });
}

This will include query parameters in the cached URL, so each unique combination of path and query parameters gets its own screenshot.

You can also selectively include only certain query parameters:

OgImage::resolveScreenshotUrlUsing(function (Request $request) {
    $url = $request->url();

    if ($request->has('category')) {
        $url .= '?category=' . $request->query('category');
    }

    return $url;
});
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai