HTML Meta Tags management package available for for Laravel 5.*

Overview

HTML Meta Tags management package available for Laravel 5/6/7/8

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')
You might also like...
Add tags and taggable behaviour to your Laravel app
Add tags and taggable behaviour to your Laravel app

Add tags and taggable behaviour to a Laravel app This package offers taggable behaviour for your models. After the package is installed the only thing

Forked from spatie-laravel-tags
Forked from spatie-laravel-tags

Add tags and taggable behaviour to a Laravel app This package offers taggable behaviour for your models. After the package is installed the only thing

A Laravel 8 and Livewire 2 demo showing how to search and filter by tags, showing article and video counts for each tag (Polymorphic relationship)
A Laravel 8 and Livewire 2 demo showing how to search and filter by tags, showing article and video counts for each tag (Polymorphic relationship)

Advanced search and filter with Laravel and Livewire A demo app using Laravel 8 and Livewire 2 showing how to implement a list of articles and tags, v

This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!
This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!

General This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform.

Tags im Museum ist ein Projekt aus dem Hackaton cdv-ost.

Tags-im-Museum Tags im Museum ist ein Projekt aus dem Hackaton cdv-ost. Vom Naturkundemuseum Leipzig wurden Tagebücher der Museumsdirektoren aus den J

A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Laravel package that converts your application into a static HTML website
Laravel package that converts your application into a static HTML website

phpReel Static Laravel Package phpReel Static is a simple Laravel Package created and used by phpReel that converts your Laravel application to a stat

 Laravel Users | A Laravel Users CRUD Management Package
Laravel Users | A Laravel Users CRUD Management Package

A Users Management Package that includes all necessary routes, views, models, and controllers for a user management dashboard and associated pages for managing Laravels built in user scaffolding. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0 and 8.0.

A Laravel package to retrieve key management from AWS Secrets Manager

A Laravel package to retrieve key management from AWS Secrets Manager Communication via AWS Secrets Manager may incur unnecessary charges. So we devel

Comments
  • Meta::set('image', 'xxxx') not working

    Meta::set('image', 'xxxx') not working

    Meta::set is not working for image.

    • PHP 7.4.0
    • Laravel 7
    >>> Meta::set('image', 'http://localhost:8000/media/1-17.png')
    => ""
    >>> Meta::get('image')
    => []
    
    opened by xyingsoft 0
Releases(v3.2.3)
Owner
Lito
Lito
Simple laravel hook for adding meta tags to head for inertia

laravel seo hook for js frameworks simple hook for adding meta tags to <head></head> for js frameworks inertia:react,vue, etc... in app/Meta.php put M

Razmik Ayvazyan 2 Aug 23, 2022
Laravel package meta 🧡

About hwa-meta is a meta package. It helps us to build and develop faster with pre-built functions. This saves a lot of time on future projects. We sh

Hwavina 3 Oct 18, 2021
A laravel package to handle model specific additional meta fields in an elegant way.

Laravel Meta Fields A php package for laravel framework to handle model meta data in a elegant way. Installation Require the package using composer: c

Touhidur Rahman 26 Apr 5, 2022
The main MageSuite (meta)package to rule them all

A Magento 2 extension ecosystem providing UX/performance improvements and many new features. This is a core metapackage which you should install in or

MageSuite 166 Dec 14, 2022
Laravel Seo package for Content writer/admin/web master who do not know programming but want to edit/update SEO tags from dashboard

Laravel Seo Tools Laravel is becoming more and more popular and lots of web application are developing. In most of the web application there need some

Tuhin Bepari 130 Dec 23, 2022
Make your church sermons available for download. For the latest version, go:

Laravel Church Sermons App Laravel church sermons app is basically an app for churches to make available the messages preached in church for all membe

Dammy 28 Nov 13, 2022
Manage meta data based on URL path within your app.

Laravel SEO Manager This package provides simple functionality to manage SEO tags based on URL path within your Laravel application. You can put the U

Michael Rubel 20 Oct 20, 2022
Clean up and prevent empty meta from being saved for Job, Company, or Resume listings in database

=== Empty Meta Cleanup for WP Job Manager === Contributors: tripflex Tags: wp job manager, meta, cleanup, wpjobmanager Requires at least: 5.2 Tested u

Myles McNamara 3 Feb 7, 2022
Laravel Nova filter for Spatie/laravel-tags

SpatieTagsNovaFilter This package allows you to filter resources by tags. (using the awesome Spatie/laravel-tags and Vue-MultiSelect ) Installation Fi

Mahi-Mahi 3 Aug 4, 2022
Html-sanitizer - The HtmlSanitizer component provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a document's DOM.

HtmlSanitizer Component The HtmlSanitizer component provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a documen

Symfony 201 Dec 23, 2022