Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-seo

> 编程语言
Open source

An SEO configuration library for Laravel applications.

354 stars0 likes0 views
WebsiteGitHub

About

An SEO configuration library for Laravel applications.

Honeystone SEO Configurator for Laravel

The Honeystone SEO package makes configuring SEO metadata from anywhere within your Laravel application a breeze.

Included are metadata generators for general metadata, X (Formally Twitter) Cards, Open Graph and JSON-LD Schema.

This package was designed with extensibility in mind, so your own custom metadata generators can also be added with ease.

Support us

We are committed to delivering high-quality open source packages maintained by the team at Honeystone. If you would like to support our efforts, simply use our packages, recommend them and contribute.

If you need any help with your project, or require any custom development, please get in touch.

Installation

bash
composer require honeystone/laravel-seo

Publish the configuration file with:

bash
php artisan vendor:publish --tag=honeystone-seo-config

Usage

The package provides a helper function, seo(), and some Blade directives, @metadata and @openGraphPrefix. You can also typehint the Honeystone\Seo\MetadataDirector if you prefer to use dependency injection.

Setting metadata is a simple as chaining methods:

php
seo()
    ->title('A fantastic blog post', 'My Awesome Website!')
    ->description('Theres really a lot of great stuff in here...')
    ->images(
        'https://mywebsite.com/images/blog-1/cover-image.webp',
        'https://mywebsite.com/images/blog-1/another-image.webp',
    );

Once you've set your metadata, you can render it using:

php
seo()->generate();

Alternatively, you can also use the @metadata Blade directive.

The rendered result will look something like this:

xml
A fantastic blog post - My Awesome Website!

Exporting metadata as arrays

Every generator now implements the Honeystone\Seo\Contracts\ExportsArrayMetadata contract, which means the director can provide a structured payload for each generator:

php
$seo = seo()->toArray();            // ['meta' => [...], 'twitter' => [...], ...]
$metaOnly = seo()->toArray('meta'); // limit to a specific generator

This is particularly useful when sharing SEO data with Inertia.js:

php
return Inertia::render('Pages/Show', [
    'page' => $page,
    'seo' => seo()->toArray(),
]);

On the client you can decide whether to render the tags yourself, hydrate a preview component, or simply inspect the payload for analytics/debugging purposes.

If you are using the bundled GenerateInertiaMetadata middleware, the structured payload is automatically shared as $page.props.seoPayload (alongside the rendered HTML string that remains available under $page.props.seo for legacy integrations).

Inertia React

When using Inertia with React, you can render the structured SEO payload directly in the head using the bundled React component at resources/js/inertia/react/SeoHead.tsx.

  1. Register the React-specific middleware \Honeystone\Seo\Http\Middleware\GenerateInertiaMetadataReact::class in your Inertia middleware stack so $page.props.seoPayload is shared:
    php
    // app/Http/Middleware/HandleInertiaRequests.php
    protected $middleware = [
        // ...
        \Honeystone\Seo\Http\Middleware\GenerateInertiaMetadataReact::class,
    ];
  2. Render the component in your React layout so every page gets the tags:
    typescript
    // resources/js/Layouts/AppLayout.tsx
    import SeoHead from '@/inertia/react/SeoHead';
    
    export default function AppLayout({ children }) {
        return (
            <>
                
                {children}
            
        );
    }
    The component reads seoPayload from usePage() and outputs meta, Open Graph, Twitter and JSON-LD tags. Pass forceNoIndex if you need to override robots for specific responses.

When using this method, Inertia itself will attempt to replace the meta tags for you so you will need to remove the @metadata blade directive from your layouts.

Default methods

Values provided to default methods will automatically propagate to all configured metadata generators.

The following default methods are available:

…

The full baseline looks like this:

xml
 A fantastic blog post 

For your homepage you'll probably want to disable the title template:

php
seo()->title('My Awesome Website!', template: false);

Meta methods

The meta methods are provided by the Honeystone\Seo\Generators\MetaGenerator class.

Here's the full list:

php
seo()
    ->metaTitle('A fantastic blog post')
    ->metaTitleTemplate(' {title} ')
    ->metaDescription('Theres really a lot of great stuff in here...')
    ->metaKeywords('foo', 'bar', 'baz')
    ->metaCanonical('https://mywebsite.com/blog/a-fantastic-blog-post')
    ->metaCanonicalEnabled(true)
    ->metaRobots('', '', '');

All of these are provided by the default methods and propagate through to the meta generator.

If you only want to render the meta generator, use seo()->generate('meta') or @metadata('meta')

Twitter methods

The meta methods are provided by the Honeystone\Seo\Generators\TwitterGenerator class.

Here's the full list:

php
seo()
    ->twitterEnabled(true) //enabled by default, see config
    ->twitterSite('@MyWebsite')
    ->twitterCreator('@MyTwitter')
    ->twitterTitle('A fantastic blog post') //defaults to title()
    ->twitterDescription('Theres really a lot of great stuff in here...') //defaults to description()
    ->twitterImage('https://mywebsite.com/images/blog-1/cover-image.webp'); //defaults to the first in images()

Open Graph methods

The meta methods are provided by the Honeystone\Seo\Generators\TwitterGenerator class.

Here's the full list:

…

You can also use the following non-vertical supported types:

…

You can provide more data for images, audio and videos using their respective properties classes:

…

Here's an example using ArticleProperties and ImageProperties:

xml

To set the prefix, you can use the @openGraphPrefix Blade directive or seo()->openGraphPrefix() like so:

xml

    ...

JSON-LD methods

The meta methods are provided by the Honeystone\Seo\Generators\JsonLdGenerator class.

Here's the full list:

…

And the output:

xml

But Wait, There's More!

Rather than reinventing the wheel, this package has support for the incredible spatie/schema-org package. You can use the jsonLdImport() method to import an exising schema, or build your schema using the fluent interface.

php
    //graph
    seo()->jsonLdGraph()
        ->organization('honeystone')
            ->name('Honeystone')
            ->legalName('Honeystone Consulting Ltd.');

    //or a MultiTypedEntity
    seo()->jsonLdMulti()
        ->organization('honeystone')
            ->name('Honeystone')
            ->legalName('Honeystone Consulting Ltd.');

Just don't forget to install the spatie/schema-org package to use this functionality.

Expectations / Check Ins

It's highly likely you'll be building your graph from many locations around your application, e.g. middleware, controllers, view composers, view components, etc.

This is where expectations come in. Simply specify your expectations, and then ensure the other parts of your application check in. If something failed to check in, an exception will be thrown. Conversely, if something unexpected checked in, an exception will also be thrown.

php
//perhaps in a controller
seo()
    ->title('Something awesome')
    ->jsonLdExpect('featured-tags', 'gallery', 'contact');

//maybe in a view composer or component
seo()
    ->jsonLdCheckIn('gallery')
    ->jsonLdGraph()
        ->imageGallery()
            ->image([
                ...
            ]);

You'll be warned immediately if 'featured-tags' or 'contact' fail to check in.

This feature is entirely optional. Just don't set any expectations, or check in, and no exceptions will be thrown.

Model integration

This package doesn't include any specific functionality for integrating models. Ultimately, you'll always need to map your model attributes to this package. For example, if your model has a meta_description attribute, you will need to map it to description, otherwise this package would not know to consume it.

With this in mind, we have a simple pattern that should get you what you need.

Start by adding a new method to your model, and set your metadata using the model's attributes within:

php
use Honeystone\Seo\MetadataDirector;
use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    public function seo(): MetadataDirector
    {
        return seo()
            ->title($this->meta_title)
            ->description($this->meta_description)
            ->jsonLdExpect('featured-items');
    }
}

Then in your controller, just call the method and chain any additional metadata:

php
use Illuminate\Contracts\View\View;

class PageController
{
    public function __invoke(Page $page): View
    {
        $page->seo()
            ->jsonLdCheckIn('featured-items')
            ->jsonLdGraph()
                ->itemList()
                    ->name('Featured items')
                    ->itemListElement([
                        //...
                    ]);
    }
}

Custom generators

To create a custom generator, simply implement the Honeystone\Seo\Contracts\MetadataGenerator contract and add it to your config file in the generators section. You can specify any configuration for your generator here too.

Removing the source comments

The package includes comments in the generated HTML. If you would like to remove them, you can publish the views and remove the comments from the Blade files:

bash
php artisan vendor:publish --tag=honeystone-seo-views

Publishing the package views is generally not recommended as these files will not be updated when the package is updated. If it is absolutely necessary to publish the views, we recommend only publishing the files you need to modify.

Configuration

Here's the full config file:

…

Changelog

A list of changes can be found in the CHANGELOG.md file.

License

MIT © George Palmer, Honeystone Consulting Ltd

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言