Handle SEO for Your Models With this Laravel Package


April 26th, 2022

Handle SEO for Your Models With this Laravel Package

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);
'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>
{!! seo()->for($post) !!}
{{-- No need to separately render a <title> tag or any other meta tags! --}}

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.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.