PHPackages                             f9webltd/laravel-meta - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. f9webltd/laravel-meta

ActiveLibrary

f9webltd/laravel-meta
=====================

Render meta tags in your Laravel application

4.0.0(2mo ago)4049.5k↓34%3[1 issues](https://github.com/f9webltd/laravel-meta/issues)MITPHPPHP ^8.2CI passing

Since May 18Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/f9webltd/laravel-meta)[ Packagist](https://packagist.org/packages/f9webltd/laravel-meta)[ Docs](https://github.com/f9webltd/laravel-meta)[ RSS](/packages/f9webltd-laravel-meta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (34)Used By (0)

[![](https://camo.githubusercontent.com/92cbde053dce891df3ee61c22aab5b65fc7971c3f08696625c4585fc354c1dd7/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304d6574612e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66397765626c74642532466c61726176656c2d6d657461267061747465726e3d627269636b57616c6c267374796c653d7374796c655f31266465736372697074696f6e3d52656e6465722b6d6574612b746167732b77697468696e2b796f75722b4c61726176656c2b6170706c69636174696f6e2532432b7573696e672b612b666c75656e742b415049266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)](https://camo.githubusercontent.com/92cbde053dce891df3ee61c22aab5b65fc7971c3f08696625c4585fc354c1dd7/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304d6574612e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d66397765626c74642532466c61726176656c2d6d657461267061747465726e3d627269636b57616c6c267374796c653d7374796c655f31266465736372697074696f6e3d52656e6465722b6d6574612b746167732b77697468696e2b796f75722b4c61726176656c2b6170706c69636174696f6e2532432b7573696e672b612b666c75656e742b415049266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)

![PHP ^8.2](https://camo.githubusercontent.com/fa17bda6467c1bb0eb1e951a14530c78330a9fb1cfa87b1918c1e33522fdb812/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d627269676874677265656e)[![Packagist Version](https://camo.githubusercontent.com/1640e68082e42fe91a5ca918adbd1a7aa30e57047cb5cc54eed0111160af8b20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66397765626c74642f6c61726176656c2d6d6574613f7374796c653d666c61742d737175617265)](https://packagist.org/packages/f9webltd/laravel-meta)[![Total Downloads](https://camo.githubusercontent.com/f3d1411a0a352c55b8545c9b371861b652df31d50350713ba3af0549cbfb5f14/68747470733a2f2f706f7365722e707567782e6f72672f66397765626c74642f6c61726176656c2d6d6574612f646f776e6c6f6164732e706e67)](https://packagist.org/packages/f9webltd/laravel-meta)[![Run Tests - Current](https://github.com/f9webltd/laravel-meta/actions/workflows/run-tests.yml/badge.svg)](https://github.com/f9webltd/laravel-meta/actions/workflows/run-tests.yml)[![StyleCI Status](https://camo.githubusercontent.com/62facaf2142e83fec7984a4386613a1f6ad9ed4c801d889c23a8b94b9e3cdbc2/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3236343937383230352f736869656c64)](https://github.styleci.io/repos/264978205)[![License](https://camo.githubusercontent.com/bfb8c6c4e1f439b67d0f34552b9e1c8b33a8856b4dc2d521e8588506284dacfe/68747470733a2f2f706f7365722e707567782e6f72672f66397765626c74642f6c61726176656c2d6d6574612f6c6963656e7365)](https://packagist.org/packages/f9webltd/laravel-meta)

Laravel Meta Tags
=================

[](#laravel-meta-tags)

Easily render meta tags within your Laravel application, using a fluent API

Features
--------

[](#features)

- Simple API
- Render named, property, raw, Twitter card and OpenGraph type meta tags
- [Optionally, render default tags on every request](#default-tags)
- [Conditionally set tags](#conditionally-setting-tags)
- [Macroable](#macroable-support)
- There is no need to set meta titles for every controller method. The package can [optionally guess titles based on uri](#meta-title) segments or the current named route
- Well documented
- Tested, with 100% code coverage

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel `^11.0`, `^12.0` or `^13.0`

### Legacy Support / Upgrading

[](#legacy-support--upgrading)

For legacy support use package version [`^3.0.0`](https://github.com/f9webltd/laravel-meta/tree/3.0.0)

See [UPGRADING](UPGRADING.md) for details on breaking changes.

Installation
------------

[](#installation)

```
composer require f9webltd/laravel-meta
```

The package will automatically register itself.

Optionally publish the configuration file by running:

```
php artisan vendor:publish --provider="F9Web\Meta\MetaServiceProvider" --tag="config"
```

Documentation
-------------

[](#documentation)

This package aims to make adding common meta tags to your Laravel application a breeze.

### Usage

[](#usage)

Within a controller:

```
meta()
   ->set('title', 'Buy widgets today')
   ->set('canonical', '/users/name')
   ->set('description', 'My meta description')
   ->set('theme-color', '#fafafa')
   ->noIndex();
```

To output metadata add the following within a Blade layout file:

```
{!! meta()->toHtml() !!}
```

```
Buy widgets today - Meta Title Append

```

Optionally, the `Meta` facade can be used as an alternative to `meta()` helper, generating the same output:

```
Meta::set('title', 'Buy widgets today')
   ->set('canonical', '/users/name')
   ->set('description', 'My meta description')
   ->set('theme-color', '#fafafa')
   ->noIndex();
```

#### Quotes

[](#quotes)

This package with handle double and single quotations within meta tag values as per Google recommendations.

The follwog code:

```
Meta::set('description', 'We sell 20" industrial nails');
```

Actual output:

```

```

### Conditionally Setting Tags

[](#conditionally-setting-tags)

The `when()` method can be used to conditionally set tags. A boolean condition (indicating if the closure should be executed) and a closure. The closure parameter is full instance of the meta class, meaning all methods are callable.

```
$noIndex = true;

meta()->when($noIndex, function ($meta) {
    $meta->noIndex();
});
```

The `when()` is fluent and can be called multiple times:

```
meta()
    ->set('title', 'the title')
    -when(true, fn ($meta) => $meta->set('og:description', 'og description'))
    -when(false, fn ($meta) => $meta->set('referrer', 'no-referrer-when-downgrade'))
    ->noIndex();
```

### Blade Directives

[](#blade-directives)

Blade directives are available, as an alternative to using PHP function within templates.

To render all metadata:

```
@meta
```

Render a specific meta tag by name:

```
@meta('title')
```

### Additional tag types

[](#additional-tag-types)

The package supports multiple tag types.

#### Property type tags

[](#property-type-tags)

To create property type tags, append `property:` before the tag name.

```
meta()->set('property:fb:app_id', '1234567890');
```

```

```

#### Twitter card tags

[](#twitter-card-tags)

To create twitter card tags, append `twitter:` before the tag name.

```
meta()->set('twitter:site', '@twitter_user');
```

```

```

#### Open Graph tags

[](#open-graph-tags)

To create Open Graph (or Facebook) tags, append `og:` before the tag name:

```
meta()
   ->set('og:title', 'My new site')
   ->set('og:url', 'http://site.co.uk/posts/hello.html');
```

```

```

#### Other tag types

[](#other-tag-types)

To create other tag types, use the `raw()` method:

```
meta()
   ->setRawTag('')
   ->setRawTag('');
```

```

```

### Default tags

[](#default-tags)

It may be desirable to render static meta tags application wide. Optionally define common tags within `f9web-laravel-meta.defaults`.

For example, defining the below defaults

```
'defaults' => [
    'robots' => 'all',
    'referrer' => 'no-referrer-when-downgrade',
    '',
],
```

will render the following on every page:

```

```

### Helper methods

[](#helper-methods)

#### `get()`

[](#get)

Fetch a specific tag value by name.

```
meta()->set('title', 'meta title');

meta()->get('title'); // meta title
```

`null` is returned for none existent tags.

#### `render()`

[](#render)

Render all defined tags. `render()` is called when rendering tags within Blade files.

The below calls are identical.

```
{!! meta()->toHtml() !!}
{!! meta()->render() !!}
```

Passing a tag title to `render()` will render that tag.

```
meta()->set('title', 'meta title');

meta()->render('title'); // meta title
```

#### `fromArray()`

[](#fromarray)

Generate multiple tags from an array of tags.

```
meta()
   ->fromArray([
       'viewport' => 'width=device-width, initial-scale=1.0',
       'author' => 'John Joe',
       'og:title' => 'When Great Minds Dont Think Alike',
       'twitter:title' => 'Using Laravel 7',
   ]);
```

```

Users - Edit - Meta Title Append
```

#### `setRawTags()`

[](#setrawtags)

Generate multiple raw tags from an array.

```
meta()
   ->setRawTags([
       '',
       '',
       ''
   ]);
```

```

```

#### `tags()`

[](#tags)

Fetch all tags as an array.

```
meta()
   ->set('title', 'meta title')
   ->set('og:title', 'og title');

$tags = meta()->tags();

/*
[
   "title" => "meta title"
   "og:title" => "og title"
];
*/
```

#### `purge()`

[](#purge)

Remove all previously set tags.

#### `forget()`

[](#forget)

Remove a previously set tag by title.

```
meta()
   ->set('title', 'meta title')
   ->set('og:title', 'og title');

meta()->forget('title');

$tags = meta()->tags();

// ["og:title" => "og title"];
```

#### `noIndex()`

[](#noindex)

Generate the necessary tags to exclude the url from search engines.

```
meta()->noIndex();
```

```

```

#### `favIcon()`

[](#favicon)

Generate the necessary tags for a basic favicon. The favicon path can be specified within the `f9web-laravel-meta.favicon-path` configuration value.

```
meta()->favIcon();
```

```

```

### Dynamic Calls

[](#dynamic-calls)

For improved readability, it is possible to make dynamic method calls. The below codes blocks would render identical HTML:

```
meta()
    ->title('meta title')
    ->description('meta description')
    ->canonical('/users/me');
```

```
meta()
    ->set('title', 'meta title')
    ->set('description', 'meta description')
    ->set('canonical', '/users/me');
```

### Macroable Support

[](#macroable-support)

The package implements Laravel's `Macroable` trait, meaning additional methods can be added the main Meta service class at run time. For example, \[Laravel's collection class is macroable\](For furtherinformatioin see the following samples ).

The `noIndex` and `favIcon` helpers are defined as macros within the [package service provider](src/MetaServiceProvider.php).

Sample macro to set arbitrary defaults tags for SEO:

```
// within a service provider
Meta::macro('seoDefaults', function () {
    return Meta::favIcon()
        ->set('title', $title = 'Widgets, Best Widgets')
        ->set('og:title', $title)
        ->set('description', $description = 'Buy the best widgets from Acme Co.')
        ->set('og:description', $description)
        ->fromarray([
            'twitter:card' => 'summary',
            'twitter:site' => '@roballport',
        ]);
});
```

To call the newly defined macro:

```
meta()->seoDefaults();
```

Macros can also accept arguments.

```
Meta::macro('setPaginationTags', function (array $data) {
    $page = $data['page'] ?? 1;

    if ($page > 1) {
        Meta::setRawTag('');
    }

    if (!empty($data['next'])) {
        return Meta::setRawTag('');
    }

    return Meta::instance();
});
```

```
meta()->setPaginationTags([
    'page' => 7,
    'next' => '/users/page/8',
    'prev' => '/users/page/6',
]);
```

To allow for fluent method calls ensure the macro returns an instance of the class.

### Special tags

[](#special-tags)

#### Meta title

[](#meta-title)

The package ensures a meta tag is always present. Omitting a title will force the package to guess one based upon the current named route or uri.

The set the preferred method, edit the `f9web-laravel-meta.title-guessor.method` configuration value.

##### `uri` method sample

[](#uri-method-sample)

- if the uri is `/orders/create` thr guessed title is "Orders - Create"
- if the uri is `/orders/9999/edit` thr guessed title is "Orders - 9999 - Edit"

##### `route` method sample

[](#route-method-sample)

- current named route is `users.create`, guessed title 'Users - Create'
- current named route is `users.index`, guessed title 'Users'

This behaviour can be disabled via editing the `f9web-laravel-meta.title-guessor.enabled` configuration value.

This automatic resolution is useful in large applications, where it would be otherwise cumbersome to set metadata for every controller method.

##### Appending text to the meta title

[](#appending-text-to-the-meta-title)

Typically, common data such as the company name is appended to meta titles.

The `f9web-laravel-meta.meta-title-append` configuration value can be set to append the given string automatically to every meta title.

To disable this behaviour set `f9web-laravel-meta.meta-title-append` to `null`.

##### Limiting the meta title length

[](#limiting-the-meta-title-length)

For SEO reasons, the meta title length should be restricted. This package, by default, limits the title to 60 characters.

To change this behaviour update the configuration value of `f9web-laravel-meta.title-limit`. Set to `null` to stop limiting.

#### Meta description

[](#meta-description)

For SEO reasons, the meta description should typically remain less than ~160 characters. This package, by default, does not limit the length.

To change the limit adjust the configuration value `f9web-laravel-meta.description-limit`. Set to `null` to stop limiting.

#### Canonical

[](#canonical)

It is important to set a sensible [canonical](https://ahrefs.com/blog/canonical-tags/). Optionally, the package can automatically replace user defined strings when generating a canonical.

Due to incorrect setup some Laravel installations allow `public` and/or `index.php` within the url.

For instance, `/users/create`, `/public/users/create` and `/public/index.php/users/create` would both be visitable, crawlable and ultimately indexable urls.

By editing the array of removable url strings within `f9web-laravel-meta.removable-uri-segments`, this behaviour can be controlled.

The package will strip `public` and `index.php` from canonical urls automatically, as a default.

Contribution
------------

[](#contribution)

Any ideas are welcome. Feel free to submit any issues or pull requests.

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Rob Allport](https://github.com/ultrono)
- [All Contributors](https://github.com/f9webltd/laravel-meta/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~180 days

Total

31

Last Release

72d ago

Major Versions

1.7.7 → 2.0.02024-03-18

2.1.0 → 3.0.02025-03-01

3.0.0 → 4.0.02026-03-08

PHP version history (4 changes)1.0.0PHP ^7.2

1.6.2PHP ^7.2 | ^8.0

2.0.0PHP ^8.0

4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/a91beab733af9a538e27dce750a4dbc1a3738d914b39dbb1f7c71475ff380109?d=identicon)[ultrono](/maintainers/ultrono)

---

Top Contributors

[![ultrono](https://avatars.githubusercontent.com/u/1782734?v=4)](https://github.com/ultrono "ultrono (35 commits)")[![joserick](https://avatars.githubusercontent.com/u/15143699?v=4)](https://github.com/joserick "joserick (1 commits)")

---

Tags

header-meta-tagslaravellaravel-meta-tagslaravel-seometameta-tagsopen-graphlaravelmetameta-tagslaravel-seolaravel metalaravel meta tagslaravel open graph tagslaravel header meta tags

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/f9webltd-laravel-meta/health.svg)

```
[![Health](https://phpackages.com/badges/f9webltd-laravel-meta/health.svg)](https://phpackages.com/packages/f9webltd-laravel-meta)
```

###  Alternatives

[cmgmyr/messenger

Simple user messaging tool for Laravel

2.6k2.4M6](/packages/cmgmyr-messenger)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
