• Stars
    star
    187
  • Rank 205,789 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTML Meta Tags management package available for for Laravel >= 5 (Including 10)

HTML Meta Tags management package available for Laravel >= 5 (Including 10)

Build Status Latest Stable Version Total Downloads License

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.

Installation

Begin by installing this package through Composer.

{
    "require": {
        "eusonlito/laravel-meta": "3.1.*"
    }
}

Laravel installation

// config/app.php

'providers' => [
    '...',
    Eusonlito\LaravelMeta\MetaServiceProvider::class
];

'aliases' => [
    '...',
    'Meta'    => Eusonlito\LaravelMeta\Facade::class,
];

Now you have a Meta facade available.

Publish the config file:

php artisan vendor:publish --provider="Eusonlito\LaravelMeta\MetaServiceProvider"

app/Http/Controllers/Controller.php

<?php namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

use Meta;

abstract class Controller extends BaseController
{
    use DispatchesCommands, ValidatesRequests;

    public function __construct()
    {
        # Default title
        Meta::title('This is default page title to complete section title');

        # Default robots
        Meta::set('robots', 'index,follow');

        # Default image
        Meta::set('image', asset('images/logo.png'));
    }
}

app/Http/Controllers/HomeController.php

<?php namespace App\Http\Controllers;

use Meta;

class HomeController extends Controller
{
    public function index()
    {
        # Section description
        Meta::set('title', 'You are at home');
        Meta::set('description', 'This is my home. Enjoy!');
        Meta::set('image', asset('images/home-logo.png'));

        return view('index');
    }

    public function detail()
    {
        # Section description
        Meta::set('title', 'This is a detail page');
        Meta::set('description', 'All about this detail page');

        # Remove previous images
        Meta::remove('image');

        # Add only this last image
        Meta::set('image', asset('images/detail-logo.png'));

        # Canonical URL
        Meta::set('canonical', 'http://example.com');

        return view('detail');
    }

    public function private()
    {
        # Section description
        Meta::set('title', 'Private Area');
        Meta::set('description', 'You shall not pass!');
        Meta::set('image', asset('images/locked-logo.png'));

        # Custom robots for this section
        Meta::set('robots', 'noindex,nofollow');

        return view('private');
    }
}

resources/views/html.php

<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::get('title') !!}</title>

        {!! Meta::tag('robots') !!}

        {!! Meta::tag('site_name', 'My site') !!}
        {!! Meta::tag('url', Request::url()); !!}
        {!! Meta::tag('locale', 'en_EN') !!}

        {!! Meta::tag('title') !!}
        {!! Meta::tag('description') !!}

        {!! Meta::tag('canonical') !!}

        {{-- Print custom section images and a default image after that --}}
        {!! Meta::tag('image', asset('images/default-logo.png')) !!}
    </head>

    <body>
        ...
    </body>
</html>

Or you can use Blade directives:

<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::get('title') !!}</title>

        @meta('robots')

        @meta('site_name', 'My site')
        @meta('url', Request::url())
        @meta('locale', 'en_EN')

        @meta('title')
        @meta('description')

        @meta('canonical')

        {{-- Print custom section images and a default image after that --}}
        @meta('image', asset('images/default-logo.png'))

        {{-- Or use @metas to get all tags at once --}}
        @metas
        
    </head>

    <body>
        ...
    </body>
</html>

MetaProduct / og:product

This will allow you to add product data to your meta data. See Open Graph product object

// resources/views/html.php

<head>
    ...
    {!! Meta::tag('type') !!} // this is needed for Meta Product to change the og:type to og:product
    {!! Meta::tag('product') !!}
</head>

Add your product data from your controller

<?php namespace App\Http\Controllers;

use Meta;

class ProductController extends Controller
{
    public function show()
    {
        # Add product meta
        Meta::set('product', [
            'price' => 100,
            'currency' => 'EUR',
        ]);
        
        # if multiple currencies just add more product metas
        Meta::set('product', [
            'price' => 100,
            'currency' => 'USD',
        ]);

        return view('index');
    }
}

Config

return [
    /*
    |--------------------------------------------------------------------------
    | 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,

    /*
    |--------------------------------------------------------------------------
    | Available Tag formats
    |--------------------------------------------------------------------------
    |
    | A list of tags formats to print with each definition
    |
    */

    'tags' => ['Tag', 'MetaName', 'MetaProperty', 'MetaProduct', 'TwitterCard'],
];

Using Meta outside Laravel

Controller

require __DIR__.'/vendor/autoload.php';

// Check default settings
$config = require __DIR__.'/src/config/config.php';

$Meta = new Eusonlito\LaravelMeta\Meta($config);

# Default title
$Meta->title('This is default page title to complete section title');

# Default robots
$Meta->set('robots', 'index,follow');

# Section description
$Meta->set('title', 'This is a detail page');
$Meta->set('description', 'All about this detail page');
$Meta->set('image', '/images/detail-logo.png');

# Canonical URL
$Meta->set('canonical', 'http://example.com');

Template

<title><?= $Meta->get('title'); ?></title>

<?= $Meta->tag('robots'); ?>

<?= $Meta->tag('site_name', 'My site'); ?>
<?= $Meta->tag('url', getenv('REQUEST_URI')); ?>
<?= $Meta->tag('locale', 'en_EN'); ?>

<?= $Meta->tag('title'); ?>
<?= $Meta->tag('description'); ?>

<?= $Meta->tag('canonical'); ?>

# Print custom section image and a default image after that
<?= $Meta->tag('image', '/images/default-logo.png'); ?>

Updates from 2.*

  • Meta::meta('title', 'Section Title') > Meta::set('title', 'Section Title')
  • Meta::meta('title') > Meta::get('title')
  • Meta::tagMetaName('title') > Meta::tag('title')
  • Meta::tagMetaProperty('title') > Meta::tag('title')

More Repositories

1

Password-Manager

Self-hosted Password Manager based on Laravel 10 + PHP 8 + MySQL 8. Gestor de Contraseñas basado en Laravel 10 + PHP 8 + MySQL 8.
PHP
164
star
2

jquery.applink

Launch native apps from web page links for mobile and desktop devices
JavaScript
135
star
3

redsys-TPV

Controlador en PHP para pasarelas de pago (TPV) Redsys / Sermepa / Servired
PHP
60
star
4

laravel-Packer

CSS, Javascript and Images packer/processors to Laravel
JavaScript
57
star
5

GPS-Tracker

GPS Tracker platform for Sinotrack ST-90x, OsmAnd and Queclink devices built with Laravel 10 + PHP 8.1 and MySQL 8. Plataforma GPS Tracker para dispositivos Sinotrack ST-90x, OsmAnd y Queclink creada con Laravel 10 + PHP 8.1 y MySQL 8.
PHP
40
star
6

Sublime-Text-ChatGPT

A Sublime Text Plugin/Package to connect with OpenAI ChatGPT
Python
25
star
7

crypto

Plataforma multiusuario para gestión de cryptos en PHP 8.1 y Laravel 10
PHP
23
star
8

Password-Manager-Chrome

Extensión de Chrome para el Gestor de Contraseñas
JavaScript
19
star
9

laravel-database-cache

Cache Database Query results on Laravel
PHP
17
star
10

php-changes-cheatsheet

HTML
16
star
11

magento2-language-es_es

Magento 2 Spanish (Spain) language package - Paquete de idioma Español (España) para Magento 2
PHP
13
star
12

redsys-Fake

Emulador de TPV redsys remoto para pruebas de pagos
PHP
12
star
13

PHPCan

A PHP Framework as tool for world domination.
PHP
11
star
14

PHPFileNavigator

PHPfileNavigator is state-of-the-art, open source web based application to complete manage your files and folders.
PHP
11
star
15

redsys-Messages

Listado de mensajes de error y pago correcto remitidos a través de Ds_Response y Ds_ErrorCode
PHP
10
star
16

laravel-Gettext

PHP
9
star
17

Ceca-TPV

Genera los formularios para la integración de la pasarela de pago de sistemas CECA
PHP
9
star
18

disposable-email-validator

Validate emails against multiple databases with disposable email domains
PHP
8
star
19

web-deploy

Easy panel to web deploy
PHP
7
star
20

Cache

PHP Cache Interface
PHP
7
star
21

invoice-api

Laravel Backend | https://invoice.lito.com.es/ | https://invoice-demo.lito.com.es/
PHP
6
star
22

php-microoptimizations

Website with PHP code comparison
PHP
6
star
23

captcha

A new simple and easy-to-implement captcha package.
PHP
6
star
24

auto-reaver

Launch reaver against all WPA/WPS discovered networks
Shell
5
star
25

invoice-vue

Vue Frontend | https://invoice.lito.com.es/ | https://invoice-demo.lito.com.es/
JavaScript
4
star
26

Apalabro

PHP project to create an Apalabrados (Angry Words) web interface.
PHP
3
star
27

facebook-birthdays

Automate the Facebook Birthdays Wishes from your own profile
PHP
3
star
28

SkyDriveAPI

Microsoft SkyDrive PHP API
PHP
2
star
29

Laravel-Domain-Scaffolding

PHP
1
star
30

Curl

A Simple Curl Interface
PHP
1
star
31

laravel-Processor

PHP
1
star
32

Gettext

A Simple Gettext Interface
PHP
1
star
33

laravel-FormManager

PHP
1
star
34

Timer

A simple timer mark script
PHP
1
star
35

Db

DB Interface Library using PDO and Respect/Relational repository
PHP
1
star
36

laravel-SimpleRoute

PHP
1
star