### Basic SEO Metadata Setup
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetadataDirector.md
A comprehensive example demonstrating how to set various SEO metadata elements including title, description, URL, images, and keywords.
```php
seo()
->title('A fantastic blog post', 'My Awesome Website!')
->description('There's really a lot of great stuff in here...')
->url('https://mywebsite.com/blog/my-post')
->images(
'https://mywebsite.com/images/blog-1/cover.webp',
'https://mywebsite.com/images/blog-1/secondary.webp'
)
->keywords('blog', 'post', 'tutorial');
```
--------------------------------
### Direct Registry Usage Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Demonstrates how to obtain the registry from the service container and use its methods to get and configure specific generators.
```php
use Honeystone\Seo\Registry;
// Get from service container (automatic)
$registry = app(RegistersGenerators::class);
// Get specific generator
$metaGen = $registry->get('meta');
$metaGen->title('My Page');
// Get all generators
foreach ($registry->all() as $generator) {
$config = $generator->config($customConfig);
}
// Selective retrieval
$some = $registry->only(['meta', 'open-graph']);
```
--------------------------------
### Complete Configuration Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
This example shows all available configuration options for the Laravel SEO package. It covers generators for meta tags, Twitter cards, Open Graph, and JSON-LD, as well as synchronization settings.
```php
[
Generators\MetaGenerator::class => [
'title' => env('APP_NAME'),
'titleTemplate' => '{title} - '.env('APP_NAME'),
'description' => 'Default site description',
'keywords' => [],
'canonicalEnabled' => true,
'canonical' => null,
'robots' => ['index', 'follow'],
'custom' => [],
],
Generators\TwitterGenerator::class => [
'enabled' => true,
'site' => '@mycompany',
'card' => 'summary_large_image',
'creator' => '@author',
'creatorId' => '',
'title' => '',
'description' => '',
'image' => '',
'imageAlt' => '',
],
Generators\OpenGraphGenerator::class => [
'enabled' => true,
'site' => env('APP_NAME'),
'type' => 'website',
'title' => '',
'description' => '',
'images' => [],
'audio' => [],
'videos' => [],
'determiner' => '',
'url' => null,
'locale' => 'en_GB',
'alternateLocales' => ['en_US'],
'custom' => [],
],
Generators\JsonLdGenerator::class => [
'enabled' => true,
'pretty' => env('APP_DEBUG'),
'type' => 'WebPage',
'name' => '',
'description' => '',
'images' => [],
'url' => null,
'custom' => [],
'place-on-graph' => true,
],
],
'sync' => [
'url-canonical' => true,
'keywords-tags' => false,
],
];
```
--------------------------------
### Example Usage of site()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Demonstrates how to set the site name using the site() method.
```php
$generator->site('My Awesome Website');
```
--------------------------------
### Honeystone SEO Configuration Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Example configuration for the honeystone-seo package, showing various options for JSON-LD generation.
```php
Generators\JsonLdGenerator::class => [
'enabled' => true,
'pretty' => env('APP_DEBUG'),
'type' => 'WebPage',
'name' => '',
'description' => '',
'images' => [],
'url' => null, // null to use current url
'custom' => [],
'place-on-graph' => true,
]
```
--------------------------------
### Configuration Example in config/honeystone-seo.php
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetaGenerator.md
This example shows how to configure the MetaGenerator within the application's configuration file, setting default values and custom meta tags.
```php
Generators\MetaGenerator::class => [
'title' => env('APP_NAME'),
'titleTemplate' => '{title} - '.env('APP_NAME'),
'description' => '',
'keywords' => [],
'canonicalEnabled' => true,
'canonical' => null, // null to use current url
'robots' => [],
'custom' => [
// [
// 'google-site-verification' => 'xxx',
// ],
],
],
```
--------------------------------
### Install Honeystone Laravel SEO Package
Source: https://github.com/honeystone/laravel-seo/blob/master/README.md
Install the package using Composer.
```shell
composer require honeystone/laravel-seo
```
--------------------------------
### OpenGraphGenerator Configuration Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
This example shows the default configuration array for the OpenGraphGenerator in the `config/honeystone-seo.php` file.
```php
Generators\OpenGraphGenerator::class => [
'enabled' => true,
'site' => env('APP_NAME'),
'type' => 'website',
'title' => '',
'description' => '',
'images' => [],
'audio' => [],
'videos' => [],
'determiner' => '',
'url' => null, // null to use current url
'locale' => '',
'alternateLocales' => [],
'custom' => [],
],
```
--------------------------------
### Synchronization Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Provides an example of how synchronization between fields can be configured. This feature helps maintain consistency between related metadata, like URL and canonical URL.
```php
'sync' => [
'url-canonical' => true, // url() ↔ canonical()
'keywords-tags' => false, // keywords → OG tags
]
```
--------------------------------
### Example Usage of image() with URL and ImageProperties
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Demonstrates setting an image using a simple URL string and a more detailed ImageProperties object.
```php
// Simple image URL
$generator->image('https://example.com/og-image.jpg');
// ImageProperties with metadata
use Honeystone\Seo\OpenGraph\ImageProperties;
$generator->image(new ImageProperties(
url: 'https://example.com/image.jpg',
alt: 'Article cover',
width: '1200',
height: '630'
));
```
--------------------------------
### Example Usage of images()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Shows how to set multiple images using an array containing URLs and ImageProperties objects.
```php
$generator->images([
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
new ImageProperties(url: 'https://example.com/image3.jpg', alt: 'Alt text')
]);
```
--------------------------------
### Example Usage of prefix()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Demonstrates how to call the prefix() method and how to use its output in an HTML head tag.
```php
// Returns: "og: https://ogp.me/ns# article: https://ogp.me/ns/article#"
echo $generator->prefix();
// Use in template:
//
```
--------------------------------
### AudioProperties Example Usage
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/types.md
Shows how to instantiate AudioProperties with audio file details and apply it using the seo() helper for Open Graph audio.
```php
$audio = new AudioProperties(
url: 'https://example.com/song.mp3',
type: 'audio/mpeg'
);
seo()->openGraphAudio($audio);
```
--------------------------------
### Per-Environment Configuration Files Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
Return different configuration arrays based on the current application environment, allowing for distinct settings in testing or production.
```php
// config/honeystone-seo.php
if (app()->environment('testing')) {
return [
'generators' => [
// Test-specific config
],
];
}
return [
// Production config
];
```
--------------------------------
### PlayerProperties Example Usage
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/types.md
Demonstrates how to create a PlayerProperties instance and use it with the seo() helper for Twitter Cards.
```php
$player = new PlayerProperties(
player: 'https://example.com/player.html',
width: '560',
height: '315',
stream: 'https://example.com/video.mp4'
);
seo()->twitterCard($player);
```
--------------------------------
### MetaGenerator Custom Meta Tags Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Example of how to define custom meta tags within the MetaGenerator configuration.
```php
'custom' => [
['google-site-verification' => 'abc123xyz'],
['author' => 'John Doe'],
],
```
--------------------------------
### Usage Example with Open Graph Images and Videos
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Shows how to add Open Graph images and videos using `ImageProperties` and `VideoProperties` for more detailed media sharing.
```php
use Honeystone\Seo\OpenGraph\ImageProperties;
use Honeystone\Seo\OpenGraph\VideoProperties;
seo()
->openGraphImage(new ImageProperties(
url: 'https://example.com/image.jpg',
width: '1200',
height: '630',
alt: 'Page preview'
))
->openGraphVideo(new VideoProperties(
url: 'https://example.com/video.mp4',
width: '1920',
height: '1080'
));
```
--------------------------------
### Example: url-canonical Sync
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Demonstrates how enabling url-canonical sync automatically sets both url() and canonical() methods when either is called.
```php
// With sync enabled
seo()->url('https://example.com/page');
// canonical is also set to https://example.com/page
seo()->canonical('https://example.com/preferred');
// url is also set to https://example.com/preferred
```
--------------------------------
### VideoProperties Example Usage
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/types.md
Illustrates creating a VideoProperties object with video specifications and setting it via the seo() helper for Open Graph video.
```php
$video = new VideoProperties(
url: 'https://example.com/video.mp4',
width: '1920',
height: '1080',
type: 'video/mp4'
);
seo()->openGraphVideo($video);
```
--------------------------------
### Rendered SEO Metadata Example
Source: https://github.com/honeystone/laravel-seo/blob/master/README.md
Example of the HTML output generated by the seo()->generate() method, including title, description, canonical, Twitter Cards, Open Graph, and JSON-LD.
```html
A fantastic blog post - My Awesome Website!
```
--------------------------------
### ImageProperties Example Usage
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/types.md
Demonstrates how to create an instance of ImageProperties and use it with the seo() helper to set Open Graph image data.
```php
$image = new ImageProperties(
url: 'https://example.com/image.jpg',
alt: 'Article cover',
width: '1200',
height: '630'
);
seo()->openGraphImage($image);
```
--------------------------------
### Configuration File Example with Environment Variables
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
The published configuration file can utilize environment variables for dynamic settings like application name and debug mode.
```php
// .env
APP_NAME="My Site"
APP_DEBUG=false
// config/honeystone-seo.php uses env()
'title' => env('APP_NAME'),
'pretty' => env('APP_DEBUG'),
```
--------------------------------
### Configure Metadata Generators
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Example configuration for metadata generators. Each generator is mapped to its class name and can be configured with specific options.
```php
'generators' => [
Generators\MetaGenerator::class => [
'title' => env('APP_NAME'),
// ...
],
Generators\TwitterGenerator::class => [
'enabled' => true,
// ...
],
// Additional generators...
],
```
--------------------------------
### OpenGraphGenerator Custom Properties Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Example of how to define custom Open Graph properties within the OpenGraphGenerator configuration.
```php
'custom' => [
['custom:field' => 'value'],
['custom:multiple' => ['value1', 'value2']],
],
```
--------------------------------
### ArticleProperties Example Usage
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/types.md
Demonstrates creating an ArticleProperties instance with publication dates, author, section, and tags, then applying it using seo()->openGraphType().
```php
$article = new ArticleProperties(
publishedTime: now(),
modifiedTime: now(),
author: new ProfileProperties(username: 'john_doe'),
section: 'Technology',
tag: ['laravel', 'seo']
);
seo()->openGraphType($article);
```
--------------------------------
### Usage Example via MetadataDirector
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Demonstrates how to set Open Graph properties using the `seo()` helper and its fluent interface for website, title, description, image, and URL.
```php
seo()
->openGraphType('website')
->openGraphSite('My Website')
->openGraphTitle('Page Title')
->openGraphDescription('Page description')
->openGraphImage('https://example.com/og-image.jpg')
->openGraphUrl('https://example.com/page');
```
--------------------------------
### Direct Usage of MetaGenerator
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetaGenerator.md
This example shows direct instantiation and usage of the MetaGenerator class to set SEO properties and generate meta tags.
```php
use Honeystone\Seo\Generators\MetaGenerator;
$meta = new MetaGenerator();
$meta->title('My Page')
->description('Page description')
->keywords(['seo', 'laravel'])
->canonical('https://example.com/page');
echo $meta->generate();
```
--------------------------------
### Example SEO HTML Output
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Middleware.md
This is an example of the HTML output generated by the GenerateInertiaMetadata middleware, including title, meta, and social tags.
```html
My Page
```
--------------------------------
### Usage via MetadataDirector Helper
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetaGenerator.md
This example demonstrates using the seo() helper function to proxy calls to MetaGenerator methods for setting SEO metadata.
```php
seo()
->metaTitle('Welcome')
->metaTitleTemplate('{title} | My Site')
->metaDescription('Welcome to our site')
->metaKeywords('welcome', 'site', 'introduction')
->metaCanonical('https://example.com/')
->metaRobots('index', 'follow');
```
--------------------------------
### Example: keywords-tags Sync
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Shows how enabling keywords-tags sync automatically applies keywords set via keywords() to Open Graph tags for Taggable types.
```php
// With sync enabled
seo()->keywords('laravel', 'seo', 'metadata');
// ArticleProperties will have these as default tags
```
--------------------------------
### Example Usage of type() with String and Object
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Shows how to set the Open Graph type using a string and an object like ArticleProperties.
```php
// String type
$generator->type('article');
// Type object
use Honeystone\Seo\OpenGraph\ArticleProperties;
$generator->type(new ArticleProperties(
publishedTime: now(),
author: new ProfileProperties(username: 'john_doe')
));
```
--------------------------------
### Rendered JSON-LD HTML Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Example of how JSON-LD structured data is typically embedded within an HTML
```
--------------------------------
### Inertia.js (React) Setup for SEO
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Integrate SEO metadata with Inertia.js applications using React. Register the middleware in `HandleInertiaRequests` and render the `SeoHead` component in your main layout.
```php
// 1. Register middleware in HandleInertiaRequests
protected $middleware = [
\Honeystone\Seo\Http\Middleware\GenerateInertiaMetadataReact::class,
];
// 2. Set SEO in controller
return inertia('Page', [
'page' => $page,
// seoPayload automatically added
]);
// 3. Render in layout
import SeoHead from '@/inertia/react/SeoHead';
export default function AppLayout({ children }) {
return (
<>
{children}
>
);
}
```
--------------------------------
### Service Container Setup in ServiceProvider
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
This code shows the service container bindings for BuildsMetadata and RegistersGenerators that occur during the ServiceProvider's register method.
```php
// ServiceProvider::register()
app()->singleton(BuildsMetadata::class, MetadataDirector::class);
app()->bind(RegistersGenerators::class, Registry::class);
```
--------------------------------
### Controller Usage with GenerateInertiaMetadata
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Middleware.md
Example of returning an Inertia response from a controller, where the 'seo' prop is automatically added by the GenerateInertiaMetadata middleware.
```php
// controller.php
return inertia('BlogPost', [
'post' => $post,
// seo prop added automatically by middleware
]);
// Blade template or component renders the HTML
```
--------------------------------
### Usage Example via MetadataDirector
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/TwitterGenerator.md
Demonstrates setting Twitter Card metadata using the global 'seo()' helper function, which likely proxies to the TwitterGenerator. Useful for setting metadata in a centralized location.
```php
seo()
->twitterSite('@mycompany')
->twitterCreator('@johndoe')
->twitterTitle('Check out this article!')
->twitterDescription('Learn SEO best practices')
->twitterImage('https://example.com/twitter-image.jpg');
```
--------------------------------
### Import or Build JSON-LD Graph with spatie/schema-org
Source: https://github.com/honeystone/laravel-seo/blob/master/README.md
Utilize the `jsonLdGraph()` or `jsonLdMulti()` methods to build JSON-LD structures, leveraging the spatie/schema-org package. Ensure the spatie/schema-org package is installed.
```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.');
```
--------------------------------
### Constructor Injection Example
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
Inject the BuildsMetadata contract directly into your controller's constructor or method for easy access to SEO functionalities.
```php
namespace App\Http\Controllers;
use Honeystone\Seo\Contracts\BuildsMetadata;
class PageController
{
public function show(BuildsMetadata $seo, Page $page)
{
$seo->title($page->title);
return view('page.show');
}
}
```
--------------------------------
### Setting Open Graph Type to Profile
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Example of setting the Open Graph type to 'profile' using ProfileProperties, including username, first name, last name, and gender.
```php
use Honeystone\Seo\OpenGraph\ProfileProperties;
$generator->type(new ProfileProperties(
username: 'john_doe',
firstName: 'John',
lastName: 'Doe',
gender: 'male'
));
```
--------------------------------
### Logging SEO Validation Errors
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/errors.md
Provides an example of using a try-catch block to log validation errors, such as UnexpectedValueExceptions, during SEO operations.
```php
use Illuminate\Support\Facades\Log;
try {
seo()->openGraphDeterminer($value)->generate();
} catch (UnexpectedValueException $e) {
Log::warning('SEO validation error: ' . $e->getMessage());
}
```
--------------------------------
### Usage with Model Data
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetaGenerator.md
This example illustrates how to dynamically set SEO metadata using data from a model, such as a post's title, excerpt, URL, and tags.
```php
// In controller
$post = Post::find(1);
seo()
->metaTitle($post->title)
->metaDescription($post->excerpt)
->metaCanonical($post->url)
->metaKeywords(...$post->tags->pluck('name')->toArray());
```
--------------------------------
### Configuration Example for TwitterGenerator
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/TwitterGenerator.md
This PHP array shows the default configuration for the TwitterGenerator in the laravel-seo package. It defines default values for various Twitter Card properties.
```php
Generators\TwitterGenerator::class => [
'enabled' => true,
'site' => '', // @twitterUsername
'card' => 'summary_large_image',
'creator' => '',
'creatorId' => '',
'title' => '',
'description' => '',
'image' => '',
'imageAlt' => '',
],
```
--------------------------------
### Setting Open Graph Type to Book
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Example of setting the Open Graph type to 'book' using BookProperties, including multiple authors, ISBN, release date, and tags.
```php
use Honeystone\Seo\OpenGraph\BookProperties;
use Honeystone\Seo\OpenGraph\ProfileProperties;
$generator->type(new BookProperties(
author: [
new ProfileProperties(firstName: 'John', lastName: 'Doe'),
new ProfileProperties(firstName: 'Jane', lastName: 'Smith')
],
isbn: '978-0201633610',
releaseDate: new DateTime('2024-01-15'),
tag: ['programming', 'design']
));
```
--------------------------------
### Create or Get Schema Org Graph
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Use the `graph()` method to obtain or create a `spatie/schema-org` Graph object. This is essential for building complex schema structures.
```php
$generator->graph()
->organization('company')
->name('My Company')
->legalName('My Company Inc.')
->email('info@example.com')
->url('https://example.com');
```
--------------------------------
### Get Open Graph Prefix for Head Tag (HTML)
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Example of how to include the Open Graph prefix in the HTML head tag using the `seo()->openGraphPrefix()` method.
```html
...
```
--------------------------------
### Controller Chaining Model SEO Methods
Source: https://github.com/honeystone/laravel-seo/blob/master/README.md
In your controller, call the model's `seo()` method and chain additional SEO configurations. This allows for dynamic SEO setup based on model data and controller logic.
```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([
//...
]);
}
}
```
--------------------------------
### Rendered HTML Example for Open Graph Meta Tags
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
This HTML snippet shows a typical set of Open Graph meta tags used for social media sharing.
```html
```
--------------------------------
### Implementing Fallback Defaults for SEO Configuration
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/errors.md
Demonstrates how to use a try-catch block to fall back to default SEO settings if an error occurs with user-provided configurations.
```php
try {
$seo = seo()->jsonLdType($userProvidedType)->generate();
} catch (RuntimeException $e) {
$seo = seo()->jsonLdType('WebPage')->generate();
}
```
--------------------------------
### get()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Retrieves a registered generator by its name.
```APIDOC
## get()
### Description
Retrieves a registered generator by its name.
### Method
`get`
### Signature
```php
public function get(string $name): GeneratesMetadata
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **name** (string) - Required - Generator identifier
### Returns
- `GeneratesMetadata` - The requested generator
### Throws
- `Undefined index` error if generator not found
### Example
```php
$metaGen = $registry->get('meta');
$twitterGen = $registry->get('twitter');
```
```
--------------------------------
### Get OpenGraphGenerator Name
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Retrieves the unique identifier for the OpenGraphGenerator.
```php
public function getName(): string
```
--------------------------------
### Access SEO Helper After Boot
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
In the `boot` method of `AppServiceProvider`, you can access the `seo()` helper function to interact with the SEO service after the package has been fully booted.
```php
// app/Providers/AppServiceProvider.php
public function boot()
{
// Access seo() helper
$seo = seo();
}
```
--------------------------------
### OpenGraphGenerator::prefix()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Gets the Open Graph namespace prefix for use in the HTML head tag.
```APIDOC
## prefix()
### Description
Gets the Open Graph namespace prefix for the head tag.
### Returns
`string` - OG prefix including type-specific namespaces if applicable.
### Example
```php
// Returns: "og: https://ogp.me/ns# article: https://ogp.me/ns/article#"
echo $generator->prefix();
// Use in template:
//
```
```
--------------------------------
### Handling Missing SEO Configuration
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/errors.md
Demonstrates how to check if the SEO configuration is loaded and log a warning if the configuration file is missing or the key is absent.
```php
$config = config('honeystone-seo', []);
if (empty($config)) {
Log::warning('SEO configuration not found. Published config file?');
}
```
--------------------------------
### Package Configuration Method
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
The configurePackage method sets up the package's name, base path, configuration file, and views.
```php
public function configurePackage(Package $package): void
{
$package
->name('honeystone-seo')
->setBasePath(dirname(__DIR__))
->hasConfigFile()
->hasViews();
}
```
--------------------------------
### Create or Get Multi-Typed Entity
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
The `multi()` method returns or creates a `spatie/schema-org` MultiTypedEntity, which is used for schemas that require multiple types.
```php
$generator->multi()
->organization('company')
->name('My Company')
->webSite()
->name('My Site')
->url('https://example.com');
```
--------------------------------
### Root Configuration Structure
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
The main configuration file defines generators and synchronization settings.
```php
return [
'generators' => [...],
'sync' => [...],
];
```
--------------------------------
### Retrieving All Generator Names
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Get a list of all registered generator names. This is useful for checking the availability of specific generators before attempting to retrieve them.
```php
$names = $registry->allNames();
// Returns: ['meta', 'twitter', 'open-graph', 'json-ld']
```
--------------------------------
### MetadataDirector Constructor
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetadataDirector.md
Initializes the MetadataDirector with a generator registry and an optional configuration repository.
```php
public function __construct(
Honeystone\Seo\Contracts\RegistersGenerators $register,
?Illuminate\Contracts\Config\Repository $config = null,
)
```
--------------------------------
### Accessing Registered Implementations
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/ServiceProvider.md
Demonstrates how to access the registered implementations of BuildsMetadata and RegistersGenerators from the application container.
```php
app(BuildsMetadata::class); // Always same instance
app(\Honeystone\Seo\MetadataDirector::class);
app(RegistersGenerators::class); // New instance each time
app(\Honeystone\Seo\Registry::class);
```
--------------------------------
### Creating Image Properties Object
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Demonstrates the instantiation of a structured object for complex metadata like images. This object encapsulates properties such as URL, width, and height.
```php
new ImageProperties(url: '...', width: '1200', height: '630')
```
--------------------------------
### Rendered HTML Meta Tags
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetaGenerator.md
This is an example of the HTML output generated by the MetaGenerator, including title, description, keywords, canonical, and robots tags.
```html
My Awesome Page
```
--------------------------------
### Configure SEO via Code (Global)
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Set SEO configuration at runtime using the `config` method. This is useful for dynamic configuration based on application state.
```php
seo()->config([
'generators' => [
MetaGenerator::class => [
'title' => 'Custom Title'
]
]
]);
```
--------------------------------
### Set Multiple Audio Files
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Sets multiple audio files, accepting an array of URLs or AudioProperties objects.
```php
$generator->audio([
'https://example.com/song1.mp3',
new AudioProperties(url: 'https://example.com/song2.mp3')
]);
```
--------------------------------
### schema()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Returns or creates a spatie/schema-org BaseType schema object. This method is used to get a base schema object that can be further customized. Certain fields are auto-populated.
```APIDOC
## schema()
### Description
Returns or creates a spatie/schema-org BaseType schema object.
### Method
```php
public function schema(): ?BaseType
```
### Returns
`Spatie\SchemaOrg\BaseType|null`
### Requires
`spatie/schema-org` package installed and `use-schema-org` config enabled
### Auto-populated fields:
- `@id` from `id()`
- `name` from `name()`
- `description` from `description()`
- `image` from `images()`
- `url` from `url()`
### Example
```php
$schema = $generator
->type('Article')
->schema();
// Schema is auto-populated, can be modified further
$schema->articleBody('Full article content');
```
```
--------------------------------
### Set Audio with Metadata
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Sets audio with metadata using the AudioProperties object. This allows for richer audio information.
```php
use Honeystone\Seo\OpenGraph\AudioProperties;
$generator->audio(new AudioProperties(
url: 'https://example.com/song.mp3',
secureUrl: 'https://example.com/song.mp3',
type: 'audio/mpeg'
));
```
--------------------------------
### Retrieving a Specific Generator
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Access a registered generator by its unique name using the get method. This allows you to directly use the generator's functionality.
```php
$metaGen = $registry->get('meta');
$twitterGen = $registry->get('twitter');
```
--------------------------------
### Fluent Interface Chaining
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Demonstrates method chaining for setting SEO properties using the fluent interface. This is the primary way to interact with the SEO builder.
```php
seo()
->title('Page')
->description('Desc')
->url('https://example.com');
```
--------------------------------
### Project File Structure
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Overview of the directory structure for the Laravel SEO project, highlighting key files and directories.
```text
output/
├── README.md ← This file
├── types.md ← All type definitions
├── configuration.md ← Configuration reference
├── errors.md ← Error handling
└── api-reference/
├── MetadataDirector.md
├── MetaGenerator.md
├── TwitterGenerator.md
├── OpenGraphGenerator.md
├── JsonLdGenerator.md
├── Registry.md
├── Middleware.md
└── ServiceProvider.md
```
--------------------------------
### Environment Variables for Configuration
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Utilize environment variables like APP_NAME and APP_DEBUG to configure application settings such as site name and JSON pretty-printing.
```bash
APP_NAME=My Website
APP_DEBUG=false
```
--------------------------------
### audio()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Sets audio files for og:audio. Accepts a single audio URL, an AudioProperties object, an array of URLs/objects, or null. This method supports chaining.
```APIDOC
## audio()
### Description
Sets audio files for og:audio.
### Method
`public function audio(string|AudioProperties|array|null $value): self`
### Parameters
#### Path Parameters
- **value** (string|AudioProperties|array|null) - Required - Audio URL(s) or AudioProperties object(s)
### Returns
`self` for method chaining
### Example
```php
// Single audio URL
$generator->audio('https://example.com/song.mp3');
// AudioProperties with metadata
use Honeystone\Seo\OpenGraph\AudioProperties;
$generator->audio(new AudioProperties(
url: 'https://example.com/song.mp3',
secureUrl: 'https://example.com/song.mp3',
type: 'audio/mpeg'
));
// Multiple audio files
$generator->audio([
'https://example.com/song1.mp3',
new AudioProperties(url: 'https://example.com/song2.mp3')
]);
```
```
--------------------------------
### Creating App Properties Object
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Shows how to create an AppProperties object for app-related metadata, such as iPhone and Google Play IDs. This is useful for app indexing and deep linking.
```php
new AppProperties(iphoneId: '123', googlePlayId: 'com.app')
```
--------------------------------
### checkIn()
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Marks a JSON-LD component as initialized, validating expectations. This method is used to confirm that specific components have been set up as expected.
```APIDOC
## checkIn()
### Description
Marks a JSON-LD component as initialized (validates expectations).
### Method
```php
public function checkIn(string ...$components): self
```
### Parameters
#### Path Parameters
- **components** (string[]) - Required - Component names being initialized
### Returns
`self` for method chaining
### Throws
`RuntimeException` if unexpected components check in
### Example
```php
// In a view composer or component
$generator->checkIn('featured-items')
->graph()
->itemList()
->name('Featured Items');
```
```
--------------------------------
### Publishing SEO Configuration
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/errors.md
Shows the Artisan command to publish the SEO configuration file, which is necessary to avoid configuration errors.
```bash
php artisan vendor:publish --tag=honeystone-seo-config
```
--------------------------------
### Basic JSON-LD Generation
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Demonstrates basic usage of the seo() helper to set JSON-LD properties like type, name, description, image, and URL.
```php
seo()
->jsonLdType('Article')
->jsonLdName('My Article')
->jsonLdDescription('Great content')
->jsonLdImage('https://example.com/article.jpg')
->jsonLdUrl('https://example.com/articles/my-article');
```
--------------------------------
### Direct Usage of TwitterGenerator
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/TwitterGenerator.md
Shows how to instantiate and use the TwitterGenerator class directly. This involves creating an instance, setting properties, and then calling generate() to output the HTML. Useful for more granular control.
```php
use Honeystone\Seo\Generators\TwitterGenerator;
$twitter = new TwitterGenerator();
$twitter->enabled(true)
->card('summary_large_image')
->site('@mysite')
->creator('@author')
->title('My Article')
->description('Great content')
->image('https://example.com/img.jpg');
echo $twitter->generate();
```
--------------------------------
### Setting Open Graph Type to Article
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Example of setting the Open Graph type to 'article' using ArticleProperties, including publication and modification times, author, section, and tags.
```php
use Honeystone\Seo\OpenGraph\ArticleProperties;
use Honeystone\Seo\OpenGraph\ProfileProperties;
$generator->type(new ArticleProperties(
publishedTime: now(),
modifiedTime: now(),
author: new ProfileProperties(username: 'john_doe'),
section: 'Technology',
tag: ['laravel', 'seo']
));
```
--------------------------------
### JSON-LD with spatie/schema-org Graph
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Shows how to use the seo() helper to generate a JSON-LD graph with multiple entities, such as an organization and a website, using the spatie/schema-org package.
```php
seo()
->jsonLdGraph()
->organization('company')
->name('My Company')
->legalName('My Company Inc.')
->url('https://example.com')
->webSite()
->name('My Website')
->url('https://example.com');
```
--------------------------------
### Mock and Test Metadata Generation
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Demonstrates how to mock the MetadataDirector for unit tests and perform real metadata assertions in feature tests. Includes clearing cached instances between tests.
```php
// Mock metadata
$this->mock(BuildsMetadata::class)
->shouldReceive('title')
->with('Test')
->andReturnSelf();
// Real metadata in feature tests
$response = $this->get('/page');
$response->assertSee('assertSee('
...
```
--------------------------------
### Get Schema Org BaseType
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/JsonLdGenerator.md
Retrieve or create a `spatie/schema-org` BaseType schema object using the `schema()` method. This method requires the `spatie/schema-org` package and `use-schema-org` config to be enabled.
```php
$schema = $generator
->type('Article')
->schema();
// Schema is auto-populated, can be modified further
$schema->articleBody('Full article content');
```
--------------------------------
### Player Card Configuration
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/TwitterGenerator.md
Configures a 'player' card type for audio or video content. Requires player URL, dimensions, and stream URL. Use the PlayerProperties class for structured input.
```php
use Honeystone\Seo\Twitter\PlayerProperties;
$generator->card(new PlayerProperties(
player: 'https://example.com/player.html',
width: '560',
height: '315',
stream: 'https://example.com/stream.mp4'
));
```
--------------------------------
### Get Open Graph Namespace Prefix
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/OpenGraphGenerator.md
Retrieves the Open Graph namespace prefix, including type-specific namespaces if configured. This is useful for setting the prefix attribute in the HTML head tag.
```php
public function prefix(): string
```
--------------------------------
### Set and Render Basic Metadata
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/README.md
Set basic SEO metadata like title, description, URL, and images using the fluent API. Render all generated metadata using the `seo()->generate()` method or the `@metadata` Blade directive.
```php
seo()
->title('My Page Title')
->description('Page description')
->url('https://example.com/page')
->images('https://example.com/image.jpg');
// Render all metadata
{{ seo()->generate() }}
// Or in Blade
@metadata
```
--------------------------------
### Dynamic Generator Methods
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/MetadataDirector.md
The MetadataDirector proxies method calls to specific generators based on a prefix. Methods starting with 'meta*', 'twitter*', 'openGraph*', or 'jsonLd*' are automatically routed to the corresponding generator.
```APIDOC
## Dynamic Generator Methods
### Description
The director uses `__call()` to proxy method calls to generators. Any method starting with a generator prefix (e.g., `meta*`, `twitter*`, `openGraph*`, `jsonLd*`) is automatically routed to that generator.
### Pattern
`{generatorPrefix}{methodName}(...$args)`
### Examples
```php
// Meta generator methods
seo()->metaTitle('Title')
->metaDescription('Description')
->metaCanonical('https://example.com');
// Twitter generator methods
seo()->twitterSite('@mysite')
->twitterCreator('@author')
->twitterImage('https://example.com/img.jpg');
// Open Graph generator methods
seo()->openGraphType('article')
->openGraphImage('https://example.com/og-image.jpg');
// JSON-LD generator methods
seo()->jsonLdType('WebPage')
->jsonLdName('My Page');
```
```
--------------------------------
### Configure JsonLdGenerator
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/configuration.md
Set up the JsonLdGenerator with options for enabling, pretty-printing, schema type, and custom properties. Defaults can be overridden via environment variables.
```php
Generators\JsonLdGenerator::class => [
'enabled' => true,
'pretty' => env('APP_DEBUG'),
'type' => 'WebPage',
'name' => '',
'description' => '',
'images' => [],
'url' => null,
'custom' => [],
'place-on-graph' => true,
]
```
--------------------------------
### Full Configuration File
Source: https://github.com/honeystone/laravel-seo/blob/master/README.md
This is the complete configuration file for the laravel-seo package. It allows customization of various SEO generators like Meta, Twitter, OpenGraph, and JsonLd.
```php
[
Generators\MetaGenerator::class => [
'title' => env('APP_NAME'),
'titleTemplate' => '{title} - '.env('APP_NAME'),
'description' => '',
'keywords' => [],
'canonicalEnabled' => true,
'canonical' => null, //null to use current url
'robots' => [],
'custom' => [
// [
// 'greeting' => 'Hey, thanks for checking out the source code of our website. '.
// 'Hopefully you find what you are looking for 👍'
// ],
// [
// 'google-site-verification' => 'xxx',
// ],
],
],
Generators\TwitterGenerator::class => [
'enabled' => true,
'site' => '', // @twitterUsername
'creator' => '',
'title' => '',
'description' => '',
'image' => '',
],
Generators\OpenGraphGenerator::class => [
'enabled' => true,
'site' => env('APP_NAME'),
'type' => 'website',
'title' => '',
'description' => '',
'images' => [],
'audio' => [],
'videos' => [],
'determiner' => '',
'url' => null, // null to use current url
'locale' => '',
'alternateLocales' => [],
'custom' => [],
],
Generators\JsonLdGenerator::class => [
'enabled' => true,
'pretty' => env('APP_DEBUG'),
'type' => 'WebPage',
'name' => '',
'description' => '',
'images' => [],
'url' => null, // null to use current url
'custom' => [],
// determines if the configured json-ld is automatically placed on the graph
'place-on-graph' => true,
],
],
'sync' => [
'url-canonical' => true,
'keywords-tags' => false,
],
];
```
--------------------------------
### Rendered HTML Example for Twitter Cards
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/TwitterGenerator.md
This HTML snippet shows the typical output generated by the TwitterGenerator, including meta tags for card type, site, creator, title, description, and image.
```html
```
--------------------------------
### Registry Constructor
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Registry.md
Initializes the Registry, automatically discovering and instantiating generators defined in the configuration.
```APIDOC
## Constructor
### Description
Initializes the Registry, automatically discovering and instantiating generators defined in the configuration.
### Signature
```php
public function __construct(?Repository $config = null)
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **config** (Repository|null) - Optional - Laravel config repository containing honeystone-seo.generators configuration
```
--------------------------------
### Custom SEO Renderer Component
Source: https://github.com/honeystone/laravel-seo/blob/master/_autodocs/api-reference/Middleware.md
Create a custom React component to manually render SEO tags. This example demonstrates updating the document title and rendering JSON-LD script tags based on the `seoPayload`.
```tsx
import { usePage } from '@inertiajs/react';
export function CustomSeoHead() {
const { seoPayload } = usePage().props;
const { meta, twitter, jsonLd } = seoPayload;
React.useEffect(() => {
// Update document title
if (meta?.title) {
document.title = meta.title;
}
// Render custom meta tags
// Render custom OG tags
// etc.
}, [seoPayload]);
return (
<>
{jsonLd?.generated && (
)}
>
);
}
```