As of August 2024, Splade is no longer actively maintained. Though we will try to keep up with future Laravel and PHP versions, we discourage using Splade in new projects.

After a period of reflection, we've come full circle and decided to bring the magic of Splade back to Inertia, where it all started. Please check out this new chapter in our journey: Inertia UI.

Title and meta tags

You may use the SEO facade to set your page's title, description, and keywords.

use ProtoneMedia\Splade\Facades\SEO;
 
class CourseController
{
public function show()
{
SEO::title('Laravel Splade Course')
->description('Become the Splade expert!')
->keywords('laravel, splade, course');
 
return view('course.show');
}
}

The keywords method accepts an array as well:

SEO::keywords(['laravel', 'splade', 'course']);

As of v1.2.11, you may also use Blade Directives to set the values within a template:

<x-layout>
@seoTitle('Laravel Splade Course')
@seoDescription('Become the Splade expert!')
@seoKeywords('laravel, splade, course')
</x-layout>

You may publish and customize the splade-seo.php configuration file to set default values. In previous versions of Splade, the SEO configuration was part of the splade.php configuration file. As of v0.6.9, there is a separate file for the SEO configuration.

php artisan vendor:publish --provider="ProtoneMedia\Splade\ServiceProvider" --tag="seo"
return [
'defaults' => [
'title' => 'My application',
 
'description' => 'This is the description of my application.',
 
'keywords' => ['application', 'keywords'],
],
];

You may also set a default prefix, suffix and separator for the title. With the example below, if you call SEO::setTitle('Home'), the final title will become Home | My app.

return [
'title_separator' => '|',
 
'title_suffix' => 'My app',
];

Canonical URL

By default, the canonical URL is set to the current URL, but you may override it with the canonical method:

SEO::canonical('https://splade.dev');

Suppose you don't want to automatically set the canonical URL to the current URL. You may disable this in the splade-seo.php config file by setting the auto_canonical_link key to false.

Open Graph tags

There are five helper methods to set Open Graph tags:

SEO::openGraphType('WebPage');
SEO::openGraphSiteName('My Application');
SEO::openGraphTitle('Home Page');
SEO::openGraphUrl('https://my.app/home');
SEO::openGraphImage(public_path('home.png'));

In the splade-seo.php configuration file, you may set default values and an auto_fill option. When you set this option to true, the value passed to the SEO::title() method will also be applied to the Open Graph Title tag.

Twitter tags

There are five helper methods to set Twitter tags:

SEO::twitterCard('summary_large_image');
SEO::twitterSite('@pascalbaljet');
SEO::twitterTitle('Home Page | My App');
SEO::twitterDescription('This is the home page of my application');
SEO::twitterImage(public_path('home.png'));

In the splade-seo.php configuration file, you may set default values and an auto_fill option. When you set this option to true, values passed to SEO::title() and SEO::description() methods will also be applied to the corresponding Twitter tags.

Custom meta tags

There are three additional methods to set other meta tags. You can set meta tags by name, property, or by giving a custom set of attributes.

SEO::metaByName('theme-color', '#ffffff');
 
SEO::metaByProperty('article:section', 'news');
 
SEO::meta([
'custom-attribute' => 'example'
]);

SEO Macro

The underlying class of the SEO facade uses Laravel's Macroable trait, so it's easy to add a method:

SEO::macro('openGraphLocale', function (string $value) {
return $this->metaByProperty('og:locale', $value);
});

Make sure to return from the callback, so you may use the facade fluently:

SEO::title('Laravel Splade Cursus')
->openGraphLocale('nl')
->description('Wil je een Splade expert worden?');