百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

seotools

> 后端框架
开源

Laravel 的 SEO 工具

3.4K stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Laravel 的 SEO 工具

SEOTools - SEO Tools for Laravel and Lumen


SEOTools is a package for [Laravel 5.8+](https://laravel.com/) and [Lumen](https://lumen.laravel.com/) that provides helpers for some common SEO techniques. > Current Build Status > Statistics [](https://packagist.org/packages/artesaos/seotools) [](https://packagist.org/packages/artesaos/seotools) [](https://packagist.org/packages/artesaos/seotools) For license information check the [LICENSE](LICENSE.md)-file. Features -------- - Friendly simple interface - Easy of set titles and meta tags - Easy of set metas for [Twitter Cards](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards) and [Open Graph](https://ogp.me/) - Easy of set for [JSON Linked Data](https://json-ld.org/) Installation ------------ ### 1 - Dependency The first step is using composer to install the package and automatically update your `composer.json` file, you can do this by running: ```shell composer require artesaos/seotools ``` > **Note**: If you are using Laravel 5.5, the steps 2 and 3, for providers and aliases, are unnecessaries. SEOTools supports Laravel new [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). ### 2 - Provider You need to update your application configuration in order to register the package so it can be loaded by Laravel, just update your `config/app.php` file adding the following code at the end of your `'providers'` section: > **Note**: If you are using Laravel 11+, you will have to update `bootstrap/providers.php` instead. [Package Discovery](https://laravel.com/docs/12.x/packages#package-discovery). > `config/app.php` ```php [ Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class, // ... ], // ... ]; ``` #### Lumen Go to `/bootstrap/app.php` file and add this line: ```php register(Artesaos\SEOTools\Providers\SEOToolsServiceProvider::class); // ... return $app; ``` ### 3 - Facades > Note: facades are not supported in Lumen. You may get access to the SEO tool services using following facades: - `Artesaos\SEOTools\Facades\SEOMeta` - `Artesaos\SEOTools\Facades\OpenGraph` - `Artesaos\SEOTools\Facades\TwitterCard` - `Artesaos\SEOTools\Facades\JsonLd` - `Artesaos\SEOTools\Facades\JsonLdMulti` - `Artesaos\SEOTools\Facades\SEOTools` You can setup a short-version aliases for these facades in your `config/app.php` file. For example: ```php [ 'SEOMeta' => Artesaos\SEOTools\Facades\SEOMeta::class, 'OpenGraph' => Artesaos\SEOTools\Facades\OpenGraph::class, 'Twitter' => Artesaos\SEOTools\Facades\TwitterCard::class, 'JsonLd' => Artesaos\SEOTools\Facades\JsonLd::class, 'JsonLdMulti' => Artesaos\SEOTools\Facades\JsonLdMulti::class, // or 'SEO' => Artesaos\SEOTools\Facades\SEOTools::class, // ... ], // ... ]; ``` ### 4 Configuration #### Publish config In your terminal type ```shell php artisan vendor:publish ``` or ```shell php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider" ``` > Lumen does not support this command, for it you should copy the file `src/resources/config/seotools.php` to `config/seotools.php` of your project In `seotools.php` configuration file you can determine the properties of the default values and some behaviors. #### seotools.php - **meta** - `defaults` - What values are displayed if not specified any value for the page display. If the value is `false`, nothing is displayed. - `webmaster` - Are the settings of tags values for major webmaster tools. If you are `null` nothing is displayed. - **opengraph** - `defaults` - Are the properties that will always be displayed and when no other value is set instead. **You can add additional tags** that are not included in the original configuration file. - **twitter** - `defaults` - Are the properties that will always be displayed and when no other value is set instead. **You can add additional tags** that are not included in the original configuration file. - **json-ld** - `defaults` - Are the properties that will always be displayed and when no other value is set instead. **You can add additional tags** that are not included in the original configuration file. Usage ----- ### Lumen Usage > Note: facades are not supported in Lumen. ```php generate(); ``` ### Meta tags Generator With **SEOMeta** you can create meta tags to the `head` ### Opengraph tags Generator With **OpenGraph** you can create OpenGraph tags to the `head` ### Twitter for Twitter Cards tags Generator With **Twitter** you can create OpenGraph tags to the `head` #### In your controller ``` … ``` #### SEOTrait ``` … ``` ### In Your View > **Pro Tip**: Pass the parameter `true` to get minified code and reduce filesize. ```html {!! SEOMeta::generate() !!} {!! OpenGraph::generate() !!} {!! Twitter::generate() !!} {!! JsonLd::generate() !!} // OR with multi {!! JsonLdMulti::generate() !!} {!! SEO::generate() !!} {!! SEO::generate(true) !!} {!! app('seotools')->generate() !!} ``` ``` … ``` #### Using Macro Using the same code in multiple places can be tedious, which is why this package includes a Macroable trait. This trait allows additional functionality to be added to a class that was not defined in the class definition, using a simple trait. For example, imagine that you need to add meta titles and descriptions for your pages. You can add your Macroable functions in the AppServiceProvider or create a dedicated file for this purpose, and define your function as shown in the code snippet: ```php SEOTools::macro('webPage', function (string $title, string $description) { SEOMeta::setTitle($title); SEOMeta::setDescription($description); SEOMeta::setCanonical('http://current.url.com'); OpenGraph::setDescription($description); OpenGraph::setTitle($title); OpenGraph::setUrl('http://current.url.com'); OpenGraph::addProperty('type', 'webpage'); }); ``` In your controller, you can use the following code to utilize the function: ```php SEOTools::webPage('Page title', 'Page description'); ``` #### API (SEOMeta) ``` … ``` #### API (OpenGraph) ``` … ``` ### API (TwitterCard) ``` … ``` ### API (JsonLd) ``` … ``` ### API (JsonLdMulti) ``` … ``` #### API (SEO) > Facilitates access to all the SEO Providers ```php Note: nowadays microdata markup is considered to be outdated. It is recommened to use [JSON Linked Data](https://json-ld.org/) instead, which is supported by this extension. ### RSS This package does not support RSS feed generation or related meta data composition. Please consider usage one of the following packages for it: - [spatie/laravel-feed](https://packagist.org/packages/spatie/laravel-feed)

Issues· 33 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPfacadejson-ldlaravellumen

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架