{"id":18606344,"url":"https://github.com/f9webltd/laravel-meta","last_synced_at":"2026-03-08T12:04:21.098Z","repository":{"id":39583814,"uuid":"264978205","full_name":"f9webltd/laravel-meta","owner":"f9webltd","description":"Laravel Meta Tags - Render meta tags within your Laravel application","archived":false,"fork":false,"pushed_at":"2025-03-01T10:15:49.000Z","size":81,"stargazers_count":40,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T18:08:25.548Z","etag":null,"topics":["header-meta-tags","laravel","laravel-meta-tags","laravel-seo","meta","meta-tags","open-graph"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f9webltd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-18T15:16:39.000Z","updated_at":"2025-03-01T10:23:54.000Z","dependencies_parsed_at":"2025-03-15T14:01:48.255Z","dependency_job_id":"f24d31aa-9099-47c9-9219-3bbce7747c0e","html_url":"https://github.com/f9webltd/laravel-meta","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f9webltd%2Flaravel-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f9webltd%2Flaravel-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f9webltd%2Flaravel-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f9webltd%2Flaravel-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f9webltd","download_url":"https://codeload.github.com/f9webltd/laravel-meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386265,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["header-meta-tags","laravel","laravel-meta-tags","laravel-seo","meta","meta-tags","open-graph"],"created_at":"2024-11-07T02:25:17.575Z","updated_at":"2026-03-08T12:04:21.087Z","avatar_url":"https://github.com/f9webltd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://banners.beyondco.de/Laravel%20Meta.png?theme=light\u0026packageManager=composer+require\u0026packageName=f9webltd%2Flaravel-meta\u0026pattern=brickWall\u0026style=style_1\u0026description=Render+meta+tags+within+your+Laravel+application%2C+using+a+fluent+API\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=code)\n\n\n[![PHP ^8.2](https://img.shields.io/badge/php-%5E8.2-brightgreen)]()\n[![Packagist Version](https://img.shields.io/packagist/v/f9webltd/laravel-meta?style=flat-square)](https://packagist.org/packages/f9webltd/laravel-meta)\n[![Total Downloads](https://poser.pugx.org/f9webltd/laravel-meta/downloads.png)](https://packagist.org/packages/f9webltd/laravel-meta)\n[![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)\n[![StyleCI Status](https://github.styleci.io/repos/264978205/shield)](https://github.styleci.io/repos/264978205)\n[![License](https://poser.pugx.org/f9webltd/laravel-meta/license)](https://packagist.org/packages/f9webltd/laravel-meta)\n\n# Laravel Meta Tags\n\nEasily render meta tags within your Laravel application, using a fluent API\n\n## Features\n\n- Simple API\n- Render named, property, raw, Twitter card and OpenGraph type meta tags\n- [Optionally, render default tags on every request](#default-tags)\n- [Conditionally set tags](#conditionally-setting-tags)\n- [Macroable](#macroable-support)\n- 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\n- Well documented\n- Tested, with 100% code coverage\n\n## Requirements\n\n- PHP `^8.2`\n- Laravel `^11.0`, `^12.0` or `^13.0`\n\n### Legacy Support / Upgrading\n\nFor legacy support use package version [`^3.0.0`](https://github.com/f9webltd/laravel-meta/tree/3.0.0)\n\nSee [UPGRADING](UPGRADING.md) for details on breaking changes.\n\n## Installation\n\n``` bash\ncomposer require f9webltd/laravel-meta\n```\n\nThe package will automatically register itself.\n\nOptionally publish the configuration file by running:\n\n```bash\nphp artisan vendor:publish --provider=\"F9Web\\Meta\\MetaServiceProvider\" --tag=\"config\"\n```\n\n## Documentation\n\nThis package aims to make adding common meta tags to your Laravel application a breeze. \n\n ### Usage\n \nWithin a controller:\n \n ```php\nmeta()\n    -\u003eset('title', 'Buy widgets today')\n    -\u003eset('canonical', '/users/name')\n    -\u003eset('description', 'My meta description')\n    -\u003eset('theme-color', '#fafafa')\n    -\u003enoIndex();\n```\n\nTo output metadata add the following within a Blade layout file:\n\n ```php\n{!! meta()-\u003etoHtml() !!}\n```\n\n ```html\n\u003ctitle\u003eBuy widgets today - Meta Title Append\u003c/title\u003e\n\u003clink rel=\"canonical\" href=\"https://site.co.uk/users/name\" /\u003e\n\u003cmeta name=\"description\" content=\"My meta description\"\u003e\n\u003cmeta name=\"theme-color\" content=\"#fafafa\"\u003e\n\u003cmeta name=\"robots\" content=\"noindex nofollow\"\u003e\n```\n\nOptionally, the `Meta` facade can be used as an alternative to `meta()` helper, generating the same output:\n\n ```php\nMeta::set('title', 'Buy widgets today')\n    -\u003eset('canonical', '/users/name')\n    -\u003eset('description', 'My meta description')\n    -\u003eset('theme-color', '#fafafa')\n    -\u003enoIndex();\n```\n\n#### Quotes\n\nThis package with handle double and single quotations within meta tag values as per Google recommendations.\n\nThe follwog code:\n\n```php\nMeta::set('description', 'We sell 20\" industrial nails');\n```\n\nActual output:\n\n```html\n\u003cmeta name=\"description\" content=\"We sell 20\u0026quot; industrial nails\"\u003e\n```\n\n### Conditionally Setting Tags\n\nThe `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.\n\n```php\n\n$noIndex = true;\n\nmeta()-\u003ewhen($noIndex, function ($meta) {\n    $meta-\u003enoIndex();\n});\n```\n\nThe `when()` is fluent and can be called multiple times:\n\n```php\nmeta()\n    -\u003eset('title', 'the title')\n    -when(true, fn ($meta) =\u003e $meta-\u003eset('og:description', 'og description'))\n    -when(false, fn ($meta) =\u003e $meta-\u003eset('referrer', 'no-referrer-when-downgrade'))\n    -\u003enoIndex();\n```\n\n### Blade Directives\n\nBlade directives are available, as an alternative to using PHP function within templates.\n\nTo render all metadata:\n\n```html\n@meta\n```\n\nRender a specific meta tag by name:\n\n```html\n@meta('title')\n```\n\n### Additional tag types\n\nThe package supports multiple tag types.\n\n#### Property type tags\n\nTo create property type tags, append `property:` before the tag name.\n\n```php\nmeta()-\u003eset('property:fb:app_id', '1234567890');\n```\n\n```html\n\u003cmeta property=\"fb:app_id\" content=\"1234567890\"\u003e\n```\n\n#### Twitter card tags\n\nTo create twitter card tags, append `twitter:` before the tag name.\n\n```php \nmeta()-\u003eset('twitter:site', '@twitter_user');\n```\n\n ```html\n\u003cmeta name=\"twitter:site\" content=\"@twitter_user\"\u003e\n```\n\n#### Open Graph tags\n\nTo create Open Graph (or Facebook) tags, append `og:` before the tag name:\n\n ```php\nmeta()\n    -\u003eset('og:title', 'My new site')\n    -\u003eset('og:url', 'http://site.co.uk/posts/hello.html');\n```\n\n ```html\n\u003cmeta property=\"og:title\" content=\"My new site\"\u003e\n\u003cmeta property=\"og:url\" content=\"http://site.co.uk/posts/hello.html\"\u003e\n```\n\n#### Other tag types\n\nTo create other tag types, use the `raw()` method:\n\n ```php\nmeta()\n    -\u003esetRawTag('\u003clink rel=\"fluid-icon\" href=\"https://gist.github.com/fluidicon.png\" title=\"GitHub\"\u003e')\n    -\u003esetRawTag('\u003clink rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/opensearch-gist.xml\" title=\"Gist\"\u003e');\n```\n\n ```html\n\u003clink rel=\"fluid-icon\" href=\"https://gist.github.com/fluidicon.png\" title=\"GitHub\"\u003e\n\u003clink rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/opensearch-gist.xml\" title=\"Gist\"\u003e\n```\n\n### Default tags\n\nIt may be desirable to render static meta tags application wide. Optionally define common tags within `f9web-laravel-meta.defaults`.\n\nFor example, defining the below defaults\n\n```php\n'defaults' =\u003e [\n    'robots' =\u003e 'all',\n    'referrer' =\u003e 'no-referrer-when-downgrade',\n    '\u003cmeta name=\"format-detection\" content=\"telephone=no\"\u003e',\n],\n```\n\nwill render the following on every page:\n\n```html\n\u003cmeta name=\"robots\" content=\"all\"\u003e\n\u003cmeta name=\"referrer\" content=\"no-referrer-when-downgrade\"\u003e\n\u003cmeta name=\"format-detection\" content=\"telephone=no\"\u003e\n```\n\n### Helper methods\n\n#### `get()`\n\nFetch a specific tag value by name.\n\n```php\nmeta()-\u003eset('title', 'meta title');\n\nmeta()-\u003eget('title'); // meta title\n```\n\n`null` is returned for none existent tags.\n\n#### `render()`\n\nRender all defined tags. `render()` is called when rendering tags within Blade files.\n\nThe below calls are identical.\n\n ```php\n{!! meta()-\u003etoHtml() !!}\n{!! meta()-\u003erender() !!}\n```\n\nPassing a tag title to `render()` will render that tag.\n\n```php\nmeta()-\u003eset('title', 'meta title');\n\nmeta()-\u003erender('title'); // \u003ctitle\u003emeta title\u003c/title\u003e\n```\n\n#### `fromArray()`\n\nGenerate multiple tags from an array of tags.\n\n ```php\nmeta()\n    -\u003efromArray([\n        'viewport' =\u003e 'width=device-width, initial-scale=1.0',\n        'author' =\u003e 'John Joe',\n        'og:title' =\u003e 'When Great Minds Dont Think Alike',\n        'twitter:title' =\u003e 'Using Laravel 7',\n    ]);\n```\n\n```html\n\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n\u003cmeta name=\"author\" content=\"John Joe\"\u003e\n\u003cmeta property=\"og:title\" content=\"When Great Minds Dont Think Alike\"\u003e\n\u003cmeta name=\"twitter:title\" content=\"Using Laravel 7\"\u003e\n\u003ctitle\u003eUsers - Edit - Meta Title Append\u003c/title\u003e\n```\n\n#### `setRawTags()`\n\nGenerate multiple raw tags from an array.\n\n ```php\nmeta()\n    -\u003esetRawTags([\n        '\u003clink rel=\"alternate\" type=\"application/rss+xml\" title=\"New Releases - Packagist\" href=\"https://packagist.org/feeds/releases.rss\" /\u003e',\n        '\u003clink rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/search.osd?v=1588083369\" title=\"Packagist\" /\u003e',\n        '\u003cmeta charset=\"UTF-8\" /\u003e'\n    ]);\n```\n\n```html\n\u003clink rel=\"alternate\" type=\"application/rss+xml\" title=\"New Releases - Packagist\" href=\"https://packagist.org/feeds/releases.rss\" /\u003e\n\u003clink rel=\"search\" type=\"application/opensearchdescription+xml\" href=\"/search.osd?v=1588083369\" title=\"Packagist\" /\u003e\n\u003cmeta charset=\"UTF-8\" /\u003e\n```\n\n#### `tags()`\n\nFetch all tags as an array.\n\n ```php\nmeta()\n    -\u003eset('title', 'meta title')\n    -\u003eset('og:title', 'og title');\n\n$tags = meta()-\u003etags();\n\n/*\n[\n    \"title\" =\u003e \"meta title\"\n    \"og:title\" =\u003e \"og title\"\n];\n*/\n```\n\n#### `purge()`\n\nRemove all previously set tags.\n\n#### `forget()`\n\nRemove a previously set tag by title.\n\n ```php\nmeta()\n    -\u003eset('title', 'meta title')\n    -\u003eset('og:title', 'og title');\n\nmeta()-\u003eforget('title');\n\n$tags = meta()-\u003etags();\n\n// [\"og:title\" =\u003e \"og title\"];\n```\n\n#### `noIndex()`\n\nGenerate the necessary tags to exclude the url from search engines.\n\n ```php\nmeta()-\u003enoIndex();\n```\n\n ```html\n\u003cmeta name=\"robots\" content=\"noindex nofollow\"\u003e\n```\n\n#### `favIcon()`\n\nGenerate the necessary tags for a basic favicon. The favicon path can be specified within the `f9web-laravel-meta.favicon-path` configuration value.\n\n ```php\nmeta()-\u003efavIcon();\n```\n\n ```html\n\u003cmeta name=\"shortcut icon\" content=\"https://site.co.uk/favicon.ico\"\u003e\n\u003clink rel=\"icon\" type=\"image/x-icon\" href=\"https://site.co.uk/favicon.ico\"\u003e\n```\n\n### Dynamic Calls\n\nFor improved readability, it is possible to make dynamic method calls. The below codes blocks would render identical HTML:\n\n```php\nmeta()\n    -\u003etitle('meta title')\n    -\u003edescription('meta description')\n    -\u003ecanonical('/users/me');\n```\n\n```php\nmeta()\n    -\u003eset('title', 'meta title')\n    -\u003eset('description', 'meta description')\n    -\u003eset('canonical', '/users/me');\n```\n\n### Macroable Support\n\nThe 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\n).\n\nThe `noIndex` and `favIcon` helpers are defined as macros within the [package service provider](src/MetaServiceProvider.php).\n\nSample macro to set arbitrary defaults tags for SEO:\n\n```php\n// within a service provider\nMeta::macro('seoDefaults', function () {\n    return Meta::favIcon()\n        -\u003eset('title', $title = 'Widgets, Best Widgets')\n        -\u003eset('og:title', $title)\n        -\u003eset('description', $description = 'Buy the best widgets from Acme Co.')\n        -\u003eset('og:description', $description)\n        -\u003efromarray([\n            'twitter:card' =\u003e 'summary',\n            'twitter:site' =\u003e '@roballport',\n        ]);\n});\n```\n\nTo call the newly defined macro:\n\n```php\nmeta()-\u003eseoDefaults();\n```\n\nMacros can also accept arguments.\n\n```php\nMeta::macro('setPaginationTags', function (array $data) {\n    $page = $data['page'] ?? 1;\n\n    if ($page \u003e 1) {\n        Meta::setRawTag('\u003clink rel=\"prev\" href=\"' . $data['prev'] . '\" /\u003e');\n    }\n\n    if (!empty($data['next'])) {\n        return Meta::setRawTag('\u003clink rel=\"next\" href=\"' . $data['next'] . '\" /\u003e');\n    }\n\n    return Meta::instance();\n});\n```\n\n```php\nmeta()-\u003esetPaginationTags([\n    'page' =\u003e 7,\n    'next' =\u003e '/users/page/8',\n    'prev' =\u003e '/users/page/6',\n]);\n```\n\nTo allow for fluent method calls ensure the macro returns an instance of the class.\n\n\n### Special tags\n\n#### Meta title\n\nThe 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.\n\nThe set the preferred method, edit the `f9web-laravel-meta.title-guessor.method` configuration value. \n\n##### `uri` method sample\n\n- if the uri is `/orders/create` thr guessed title is \"Orders - Create\"\n- if the uri is `/orders/9999/edit` thr guessed title is \"Orders - 9999 - Edit\"\n\n##### `route` method sample\n\n- current named route is `users.create`, guessed title 'Users - Create'\n- current named route is `users.index`, guessed title 'Users'\n\nThis behaviour can be disabled via editing the `f9web-laravel-meta.title-guessor.enabled` configuration value.\n\nThis automatic resolution is useful in large applications, where it would be otherwise cumbersome to set metadata for every controller method.\n \n##### Appending text to the meta title\n\nTypically, common data such as the company name is appended to meta titles.\n \n The `f9web-laravel-meta.meta-title-append` configuration value can be set to append the given string automatically to every meta title. \n \n To disable this behaviour set `f9web-laravel-meta.meta-title-append` to `null`.\n  \n##### Limiting the meta title length\n\nFor SEO reasons, the meta title length should be restricted. This package, by default, limits the title to 60 characters.\n\nTo change this behaviour update the configuration value of `f9web-laravel-meta.title-limit`. Set to `null` to stop limiting.\n\n#### Meta description\n \nFor SEO reasons, the meta description should typically remain less than ~160 characters. This package, by default, does not limit the length.\n \nTo change the limit adjust the configuration value `f9web-laravel-meta.description-limit`. Set to `null` to stop limiting.\n\n#### Canonical\n\nIt 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.\n\nDue to incorrect setup some Laravel installations allow `public` and/or `index.php` within the url.\n\nFor instance, `/users/create`, `/public/users/create` and `/public/index.php/users/create` would both be visitable, crawlable and ultimately indexable urls.\n\nBy editing the array of removable url strings within `f9web-laravel-meta.removable-uri-segments`, this behaviour can be controlled.\n\nThe package will strip `public` and `index.php` from canonical urls automatically, as a default.\n\n## Contribution\n\nAny ideas are welcome. Feel free to submit any issues or pull requests.\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Security\n\nIf you discover any security related issues, please email rob@f9web.co.uk instead of using the issue tracker.\n\n## Credits\n\n- [Rob Allport](https://github.com/ultrono)\n- [All Contributors](https://github.com/f9webltd/laravel-meta/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff9webltd%2Flaravel-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff9webltd%2Flaravel-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff9webltd%2Flaravel-meta/lists"}