noith / meta
Laravel meta tag manager for canonical, robots, and hreflang tags.
Requires
- php: >=8.2
- laravel/framework: ^12.0 || ^13.0
Requires (Dev)
- orchestra/testbench: ^10.8
- phpunit/phpunit: ^12.5
This package is auto-updated.
Last update: 2026-08-06 16:21:03 UTC
README
Small Laravel package for rendering canonical, robots, and hreflang meta tags from request-scoped managers.
Requirements
- PHP 8.2 or higher
- Laravel 12.x or 13.x
Installation
composer require noith/meta
The service provider and facade are auto-discovered by Laravel.
Publish the config when you need to change defaults:
php artisan vendor:publish --tag=meta-config
Configuration
return [
'canonical' => [
'enabled' => true,
],
'robots' => [
'default' => 'index, follow',
'enabled' => true,
],
'hreflang' => [
'enabled' => true,
],
];
Rendering Tags
Place the Blade components in your layout <head>:
<x-meta::canonical />
<x-meta::robots />
<x-meta::hreflang />
Usage
Set values with helpers:
canonical('https://example.com/products');
robots('noindex,nofollow');
robots_merge('noarchive');
hreflang('en', 'https://example.com/en/products');
hreflang('fr', 'https://example.com/fr/products');
Use the facade when chaining is more convenient:
use Noith\Meta\Facades\Meta;
Meta::canonical('https://example.com/products')
->robots('index,follow')
->mergeRobots('noarchive')
->hreflang('en', 'https://example.com/en/products');
robots_merge() adds directives without replacing the whole value. When a known opposite directive exists, it is removed first. For example, merging noindex into the default index, follow produces follow, noindex.
Canonical URLs
If no explicit canonical URL is set, the package uses the current request URL. Query parameters are removed unless they are explicitly allowed:
app(Noith\Meta\CanonicalManager::class)
->addAllowedParams(['page', 'sort']);
Robots Middleware
The package registers the robots middleware alias:
Route::get('/private', PrivatePageController::class)
->middleware('robots:robots=noindex,nofollow');
Route::get('/preview', PreviewController::class)
->middleware('robots:robots=noindex,nofollow;googlebot=noindex');
Testing
The package registers response assertions:
$response->assertCanonical('https://example.com/products');
$response->assertRobots('noindex, nofollow');
$response->assertHreflang('en', 'https://example.com/en/products');
Run the test suite:
./vendor/bin/phpunit