SEOTools

repository·master·Indexed 25 days ago

https://github.com/artesaos/seotools

A package for Laravel and Lumen that simplifies the management and generation of SEO meta tags, OpenGraph, Twitter Cards, and JSON-LD structured data. It provides facades for SEOMeta, OpenGraph, TwitterCard, and JsonLd, along with a unified SEOTools facade and a SEOTrait for controller integration.

Tokens
6.6K
Snippets
11
Records
49
Agent score
85%

What's inside artesaos/seotools

  1. Configure SEOTools

    master

    Publish the configuration file to your project using Artisan:

    php artisan vendor:publish --provider="Artesaos\SEOTools\Providers\SEOToolsServiceProvider"

    Note for Lumen: Lumen does not support vendor:publish. Manually copy src/resources/config/seotools.php to config/seotools.php in your project.

    In seotools.php, you can configure:

    • meta.defaults: Values displayed if none are specified.
    • meta.webmaster: Settings for major webmaster tools.
    • opengraph.defaults: Properties always displayed (you can add custom tags here).
    • twitter.defaults: Properties always displayed (you can add custom tags here).
    • json-ld.defaults: Properties always displayed (you can add custom tags here).
  2. Install SEOTools in Laravel

    master

    Install the package via Composer to update your composer.json file.

    If you are using Laravel 5.5+, Package Discovery will automatically handle the provider and aliases. For older versions or manual setup, you must register the provider in config/app.php (or bootstrap/providers.php for Laravel 11+).

    composer require artesaos/seotools
  3. Generate SEO tags in Blade views

    master

    To output the generated tags in your HTML <head>, use the generate() method. You can pass true to get minified code.

    Laravel (Facades):

    {!! SEOMeta::generate() !!}
    {!! OpenGraph::generate() !!}
    {!! Twitter::generate() !!}
    {!! JsonLd::generate() !!}
    {!! SEO::generate() !!}
    {!! SEO::generate(true) !!} <!-- Minified -->

    Lumen:

    {!! app('seotools')->generate() !!}
    <head>
        {!! SEO::generate() !!}
    </head>
  4. Extend SEOTools using Macros

    master

    Since the package uses the Macroable trait, you can define custom SEO methods in your AppServiceProvider.

    // In AppServiceProvider
    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 Controller
    SEOTools::webPage('Page title', 'Page description');
  5. Use SEOTools in Lumen

    master

    Since Lumen does not support facades, use the app() helper to access the services:

    $seotools = app('seotools');
    $metatags = app('seotools.metatags');
    $twitter = app('seotools.twitter');
    $opengraph = app('seotools.opengraph');
    $jsonld = app('seotools.json-ld');
    $jsonldMulti = app('seotools.json-ld-multi');
    
    echo app('seotools')->generate();
  6. Use the SEOTools Facade for unified access

    master

    The SEOTools facade provides a single entry point to access all SEO providers.

    use Artesaos\SEOTools\Facades\SEOTools;
    
    SEOTools::setTitle('Home');
    SEOTools::setDescription('Description');
    SEOTools::opengraph()->setUrl('http://current.url.com');
    SEOTools::twitter()->setSite('@LuizVinicius73');
    SEOTools::jsonLd()->setType('Article');
    
    // Access specific providers
    SEOTools::metatags();
    SEOTools::twitter();
    SEOTools::opengraph();
    SEOTools::jsonLd();
  7. Add SEO functionality via SEOTrait

    master

    You can use the SEOTools trait in your controllers to access SEO methods via $this->seo().

    namespace App\Http\Controllers;
    
    use Artesaos\SEOTools\Traits\SEOTools as SEOToolsTrait;
    
    class CommonController extends Controller
    {
        use SEOToolsTrait;
    
        public function index()
        {
            $this->seo()->setTitle('Home');
            $this->seo()->twitter()->setSite('@LuizVinicius73');
        }
    }