Installing Mentola SEO in a Laravel application
The package mentola/laravel-seo renders what you publish in Mentola, serves sitemaps and redirects, and keeps your site working when Mentola is unreachable. This page is the complete setup.
Requirements
- Laravel 11 or 12, PHP 8.2 or newer.
- MySQL or MariaDB (SQLite works for local development).
- Ordinary PHP hosting is enough. No Node, Redis or persistent worker is needed.
- A Mentola account with the website added and verified, and a site token from the website's Connect screen.
1. Install
composer require mentola/laravel-seo php artisan vendor:publish --tag=mentola-seo-config php artisan migrate
The migration adds four tables prefixed mentola_seo_: metadata, redirects, 404 telemetry and sync state. Nothing else in your schema is touched.
2. Configure
# .env MENTOLA_SEO_TOKEN=mseo_... # from Mentola, shown once MENTOLA_SEO_ENDPOINT=https://marketing.mentola.com/api/seo/v1 MENTOLA_SEO_SITE=site_... # the website's id in Mentola MENTOLA_SEO_SITE_NAME="Your company" # used by the title template
Defaults for the title template, description, robots directive, Open Graph image and locales live in config/mentola-seo.php. Values you publish in Mentola override them per page; what you set locally always wins over what the handshake suggests.
3. Render the head
Replace hand-written title and meta tags in your layout with the component:
<head>
<meta charset="utf-8">
<x-mentola-seo::head />
</head>
It renders the title (through the template), meta description, canonical, robots, Open Graph and Twitter tags, hreflang alternates with x-default, and JSON-LD. Resolution order on every request: values you set in code, then a model implementing SeoSubject, then metadata synced from Mentola for the current route, then route-level config, then the global defaults.
4. Register the middleware
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->prepend(\Mentola\Seo\Http\Middleware\HandleRedirects::class);
$middleware->web(append: [\Mentola\Seo\Http\Middleware\ResolveSeoContext::class]);
$middleware->append(\Mentola\Seo\Http\Middleware\RecordNotFound::class); // optional
})
HandleRedirects applies the rules you manage in Mentola (and any you add locally) before routing. ResolveSeoContext works out which page is being rendered. RecordNotFound counts 404s, throttled and without query strings, so Mentola can show you which old addresses people still hit.
5. Introduce the package and sync
php artisan mentola-seo:handshake # marks the site connected in Mentola php artisan mentola-seo:sync # pushes your page inventory, pulls published metadata php artisan mentola-seo:status # what is cached locally, when it last synced
Schedule the sync so changes you publish in Mentola reach the site within the hour:
// routes/console.php
Schedule::command('mentola-seo:sync')->hourly();
On hosting without cron, call php artisan schedule:run from whatever clock you have, or run mentola-seo:sync from a deploy hook.
Per-page values in code
use Mentola\Seo\Facades\Seo;
Seo::title('Plumbing in Aarhus')
->description('Leak repairs and new bathrooms, same week, fixed price.')
->image('/img/team.jpg')
->jsonLd(['@type' => 'LocalBusiness', 'name' => 'Nordlys']);
Models
use Mentola\Seo\Concerns\HasSeo;
class Article extends Model
{
use HasSeo;
public function seoDefaults(): array
{
return ['title' => $this->headline, 'description' => $this->summary];
}
}
A model with HasSeo gets a stable locator (model:article|42) that Mentola uses to attach published metadata, and can be listed as a sitemap source in config.
Sitemaps
/sitemap.xml is served by the package from the routes you list in config, from classes implementing SitemapSource, and from HasSeo models. Several sources or more than 50,000 URLs produce a sitemap index with named chunks. Responses are cached; the TTL is configurable.
Redirects
Rules created in Mentola are pulled on every sync and applied by the middleware with the status code you chose. Loops and chains are refused when you create them. Local rules added in code with RedirectRepository::put() are kept and never overwritten by Mentola.
Verification by package
The package answers at /.well-known/mentola-seo.json with your site's verification token after the first handshake. In Mentola, choose "Laravel package" on the Verify screen and check. This proves control of the application that serves the host, which is a stronger claim than a meta tag.
When Mentola is unreachable
Pages render from the local tables. Sitemaps and redirects are served from the same tables. The sync command exits non-zero with a readable error and prints nothing secret. Telemetry (404s, redirect hits) is kept and uploaded on the next successful sync, so nothing is lost or double counted.
Upgrading
The package sends its version on every handshake. If Mentola needs a newer one, the handshake response says so and the status command shows it. Minor versions never change the local schema without a migration you run yourself.