zanysoft/laravel-meta-tags is a Laravel package for a package to manage header meta tags.
It currently has 2 GitHub stars and 476 downloads on Packagist (latest version 1.0.5).
Install it with composer require zanysoft/laravel-meta-tags.
Discover more Laravel packages by zanysoft
or browse all Laravel packages to compare alternatives.
Last updated
With this package you can manage header Meta Tags from Laravel controllers.
From the command line run
$ composer require zanysoft/laravel-meta-tags
Once Meta Tags is installed you need to register the service provider with the application. Open up config/app.php and find the providers key.
'providers' => array(
ZanySoft\LaravelMetaTags\MetaTagsServiceProvider::class,
)
Meta Tags also ships with a facade which provides the static syntax for creating collections. You can register the facade in the aliases key of your config/app.php file.
'aliases' => array(
'MetaTag' => ZanySoft\LaravelMetaTags\Facades\MetaTag::class,
)
Run this on the command line from the root of your project:
$ php artisan vendor:publish --provider="ZanySoft\LaravelMetaTags\MetaTagsServiceProvider"
A configuration file will be publish to config/meta-tags.php.
Trialing slash Configuration
If you want to add trialing slash to home url then set this to true (if not exist in config file add this)
'add_trialing_slash' => false,
If you want to add query strings to canonical url then set this to true (if not exist in config file add this)
'canonical_query_string' => false,
Various settings for these options can be found in the config/meta-tags.php file.
Twitter Cards
{!! MetaTag::twitterCard() !!}
OpenGraph
{!! MetaTag::openGraph() !!}
For All
{!! MetaTag::renderAll() !!}
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use MetaTag;
abstract class Controller extends BaseController
{
use ValidatesRequests;
public function __construct()
{
// Defaults
MetaTag::set('description', 'Blog Wes Anderson bicycle rights, occupy Shoreditch gentrify keffiyeh.');
MetaTag::set('image', asset('images/default-share-image.png'));
}
}
<?php
namespace App\Http\Controllers;
use MetaTag;
class HomeController extends Controller
{
public function index()
{
// Section description
MetaTag::set('title', 'You are at home');
MetaTag::set('description', 'This is my home. Enjoy!');
return view('index');
}
public function detail()
{
// Section description
MetaTag::set('title', 'This is a detail page');
MetaTag::set('description', 'All about this detail page');
MetaTag::set('image', asset('images/detail-logo.png'));
return view('detail');
}
public function private()
{
// Section description
MetaTag::set('title', 'Private Area');
MetaTag::set('description', 'You shall not pass!');
MetaTag::set('image', asset('images/locked-logo.png'));
return view('private');
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ MetaTag::get('title') }}</title>
{!! MetaTag::tag('description') !!}
{!! MetaTag::tag('image') !!}
{!! MetaTag::canonical() !!}
{!! MetaTag::openGraph() !!}
{!! MetaTag::twitterCard() !!}
{{--Set default share picture after custom section pictures--}}
{!! MetaTag::tag('image', asset('images/default-logo.png')) !!}
</head>
<body>
@yield('content')
</body>
</html>