metasyncsite / laravel-metasync-client
Laravel client for MetaSync: sync page meta tags and redirects with the MetaSync SaaS
Package info
github.com/metasyncSite/laravel-metasync-client
pkg:composer/metasyncsite/laravel-metasync-client
Requires
- php: ^8.2
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Syncs your Laravel site's meta tags and redirects with MetaSync.
Installation
composer require metasyncsite/laravel-metasync-client php artisan migrate
.env:
METASYNC_URL=https://app.metasync.site
METASYNC_TOKEN=<project token from MetaSync>
Exposing your pages (required for push)
Implement the PageCollector contract — it yields the site's pages:
use MetaSyncClient\Contracts\PageCollector; class AppPageCollector implements PageCollector { public function collect(): iterable { foreach (Product::query()->cursor() as $product) { yield [ 'url_path' => '/products/'.$product->slug, 'lang' => 'uk', 'page_type' => 'product', 'title' => $product->meta_title, 'description' => $product->meta_description, 'h1' => $product->name, 'http_status' => 200, ]; } } }
Then bind it in AppServiceProvider::register():
$this->app->bind(PageCollector::class, AppPageCollector::class);
Commands
| Command | Description |
|---|---|
metasync:push [--dry-run] |
Push the site's pages to MetaSync |
metasync:pull [--full] |
Pull edited meta and redirects into the local cache tables |
metasync:sync |
push + pull |
metasync:webhook [url] [--remove] |
Register a webhook for instant change delivery |
metasync:pull registers itself on the scheduler every 15 minutes as a fallback for when the webhook cannot reach the site (disable with METASYNC_SCHEDULE_PULL=false, change the schedule with METASYNC_SCHEDULE_CRON).
Rendering meta on pages
The simplest way is the directive in your layout's <head> — it outputs <title>, description and robots, and renders nothing for pages without an entry:
<head> @metasyncHead </head>
Or resolve entries directly via the facade or resolver (prefers the exact language with a fallback to any; tolerates a trailing-slash mismatch):
$meta = MetaSync::forRequest(); // or app(\MetaSyncClient\MetaResolver::class) $meta = MetaSync::forPath('/about', 'uk');
<title>{{ $meta?->title ?? config('app.name') }}</title> @if($meta?->description)<meta name="description" content="{{ $meta->description }}">@endif @if($meta?->noindex)<meta name="robots" content="noindex">@endif <h1>{{ $meta?->h1 ?? $product->name }}</h1>
Redirects
The HandleRedirects middleware registers automatically (disable with METASYNC_REDIRECTS=false) and applies active redirects from MetaSync to all GET requests.
Instant change delivery
php artisan metasync:webhook— registersPOST /metasync/webhookin MetaSync and prints the secret.- Add
METASYNC_WEBHOOK_SECRET=...to your.env. - When meta changes in MetaSync, the service pings your site, the package queues a pull and the changes apply automatically.
Tests
composer install
composer test