With this package you can manage header Meta Tags from Laravel controllers.
If you want a Laravel <= 4.2 compatible version, please use v4.2
branch.
Begin by installing this package through Composer.
{
"require": {
"laravel/meta": "master-dev"
}
}
// config/app.php
'providers' => [
'...',
'Laravel\Meta\MetaServiceProvider',
];
'aliases' => [
'...',
'Meta' => 'Laravel\Meta\Facade',
];
Now you have a Meta
facade available.
Publish the config file:
php artisan vendor:publish
<?php namespace App\Http\Controllers;
use Meta;
class Home extends Controller {
public function __construct()
{
# Default title
Meta::title('This is default page title to complete section title');
# Default robots
Meta::meta('robots', 'index,follow');
}
public function index()
{
# Section description
Meta::meta('title', 'You are at home');
Meta::meta('description', 'This is my home. Enjoy!');
Meta::meta('image', asset('images/home-logo.png'));
return view('index');
}
public function detail()
{
# Section description
Meta::meta('title', 'This is a detail page');
Meta::meta('description', 'All about this detail page');
Meta::meta('image', asset('images/detail-logo.png'));
return view('detail');
}
public function private()
{
# Section description
Meta::meta('title', 'Private Area');
Meta::meta('description', 'You shall not pass!');
Meta::meta('image', asset('images/locked-logo.png'));
# Custom robots for this section
Meta::meta('robots', 'noindex,nofollow');
return view('private');
}
}
<html>
<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" />
<meta name="author" content="Lito - [email protected]" />
<title><?= Meta::meta('title'); ?></title>
<?= Meta::tagMetaName('robots'); ?>
<?= Meta::tagMetaProperty('site_name', 'My site'); ?>
<?= Meta::tagMetaProperty('url', Request::url()); ?>
<?= Meta::tagMetaProperty('locale', 'en_EN'); ?>
<?= Meta::tag('title'); ?>
<?= Meta::tag('description'); ?>
<?= Meta::tag('image'); ?>
# Set default share picture after custom section pictures
<?= Meta::tag('image', asset('images/default-logo.png')); ?>
</head>
<body>
...
</body>
</html>
return array(
/*
|--------------------------------------------------------------------------
| Limit title meta tag length
|--------------------------------------------------------------------------
|
| To best SEO implementation, limit tags.
|
*/
'title_limit' => 70,
/*
|--------------------------------------------------------------------------
| Limit description meta tag length
|--------------------------------------------------------------------------
|
| To best SEO implementation, limit tags.
|
*/
'description_limit' => 200,
/*
|--------------------------------------------------------------------------
| Limit image meta tag quantity
|--------------------------------------------------------------------------
|
| To best SEO implementation, limit tags.
|
*/
'image_limit' => 5
);
require (__DIR__.'/vendor/autoload.php');
// Check default settings
$config = require (__DIR__.'/src/config/config.php');
$Meta = new Laravel\Meta\Meta($config);
# Default title
$Meta->title('This is default page title to complete section title');
# Default robots
$Meta->meta('robots', 'index,follow');
# Section description
$Meta->meta('title', 'This is a detail page');
$Meta->meta('description', 'All about this detail page');
$Meta->meta('image', '/images/detail-logo.png');
<title><?= $Meta->meta('title'); ?></title>
<?= $Meta->tagMetaName('robots'); ?>
<?= $Meta->tagMetaProperty('site_name', 'My site'); ?>
<?= $Meta->tagMetaProperty('url', getenv('REQUEST_URI')); ?>
<?= $Meta->tagMetaProperty('locale', 'en_EN'); ?>
<?= $Meta->tag('title'); ?>
<?= $Meta->tag('description'); ?>
<?= $Meta->tag('image'); ?>
# Set default share picture after custom section pictures
<?= $Meta->tag('image', '/images/default-logo.png'); ?>