• Reading time ~ 1 min
  • 26.06.2022

The laravel-seo package handles the SEO in any Laravel application, big or small:

Currently there aren't that many SEO-packages for Laravel and the available ones are quite complex to set up and very decoupled from the database. They only provided you with helpers to generate the tags, but you still had to use those helpers: nothing was generated automatically and they almost do not work out of the box.

With a bit of configuration, this package offers the following out of the box:

  1. Robots tag
  2. Title tag (with sitewide suffix)
  3. Meta tags (author, description, image, etc.)
  4. OpenGraph Tags (Facebook, LinkedIn, etc.)
  5. Twitter Tags
  6. Structured data (Article and Breadcrumbs)
  7. Favicon

This package connects SEO data to models. For example, if you have a Post model, you can add/update/read SEO data:

$post = Post::find(1);
 
$post->seo->update([
   'title' => 'My great post',
   'description' => 'This great post will enhance your live.',
]);
 
// Access the SEO relationship
$seo = $post->seo;

You can also dynamically retrieve this data in a model using the following method:

use RalphJSmit\Laravel\SEO\Support\HasSEO;
 
class Post extends Model
{
    use HasSEO;
 
    public function getDynamicSEOData(): SEOData
    {
        $pathToFeaturedImageRelativeToPublicPath = // ..;
 
        // Override only the properties you want:
        return new SEOData(
            title: $this->title,
            description: $this->excerpt,
            image: $pathToFeaturedImageRelativeToPublicPath,
        );
    }
}

Then on the frontend you can use the seo() helper to render HTML tags:

<!DOCTYPE html>
<html>
<head>
    {!! seo()->for($post) !!}
 
    {{-- No need to separately render a <title> tag or any other meta tags! --}}
</head>

The package's readme has more examples, including advanced usage details. You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297