ralphjsmit/laravel-filament-seo
Filament field group for editing laravel-seo metadata (title, author, description). Automatically loads/saves via the model’s seo() relationship—just add HasSEO to your Eloquent model and drop SEO::make() into any Filament form.
Installation
composer require ralphjsmit/laravel-filament-seo
Publish the config file:
php artisan vendor:publish --provider="RalphJSmit\FilamentSEO\FilamentSEOServiceProvider" --tag="filament-seo-config"
Configure SEO Fields
Edit config/filament-seo.php to define default SEO fields (e.g., title, description, keywords, meta_tags).
Add to a Filament Resource
Use the HasSEO trait in your Filament resource (compatible with Laravel 10+ and now Laravel 13):
use RalphJSmit\FilamentSEO\Concerns\HasSEO;
class PageResource extends Resource
{
use HasSEO;
// ...
}
First Use Case Access SEO fields in your Filament panel via the "SEO" tab (auto-generated). Edit meta tags directly from the admin UI.
Resource Integration
Extend any Filament resource with HasSEO to expose SEO fields:
public static function form(Form $form): Form
{
return $form
->schema([
// ... other fields
SEOFields::make(),
]);
}
Customizing SEO Fields
Override defaults in config/filament-seo.php or dynamically:
SEOFields::make([
'title' => 'Custom Title Field',
'description' => 'Custom Description',
'canonical' => 'Canonical URL',
]);
Conditional SEO Hide/show SEO fields based on logic:
SEOFields::make()->visible(fn ($record) => $record->is_published)
Syncing with Laravel SEO
Use the underlying spatie/laravel-seo package for model binding (ensure compatibility with Laravel 13):
public static function getRelations(): array
{
return [
Seo::class, // Spatie's SEO model
];
}
Bulk SEO Updates Leverage Filament’s bulk actions to update SEO metadata for multiple records:
public static function table(Table $table): Table
{
return $table
->actions([
Tables\Actions\EditAction::make(),
SEOBulkAction::make(), // Hypothetical bulk SEO editor
]);
}
Missing Config
Forgetting to publish the config (filament-seo.php) will default to empty SEO fields. Always run:
php artisan vendor:publish --tag="filament-seo-config"
Laravel 13 Compatibility Ensure your project is upgraded to Laravel 13 if leveraging new features. Test thoroughly for any breaking changes in Filament or Spatie packages.
Model Binding Conflicts
If using spatie/laravel-seo, ensure your model’s seo() relationship matches the package’s expectations:
public function seo()
{
return $this->morphOne(Seo::class, 'model');
}
Caching Issues SEO fields may not reflect changes immediately due to Filament’s caching. Clear the view cache:
php artisan view:clear
Overriding Defaults
Customizing SEO fields via config/filament-seo.php does not automatically update existing database records. Use migrations or seeders to backfill data:
Seo::create([
'title' => 'Default Title',
'description' => 'Default Description',
'model_type' => YourModel::class,
'model_id' => $record->id,
]);
HasSEO trait is used and the resource’s form() includes SEOFields::make().dd() in your model’s seo() relationship to inspect bound data.php artisan optimize:clear if encountering issues with new Laravel 13 features.Custom SEO Fields
Extend the SEOFields class to add custom meta tags:
class CustomSEOFields extends SEOFields
{
public static function make(): array
{
return array_merge(parent::make(), [
TextInput::make('twitter_card')->label('Twitter Card'),
]);
}
}
Validation Rules
Add validation to SEO fields in your resource’s form():
SEOFields::make()->columns(2)
->rules([
'title' => 'required|max:60',
'description' => 'required|max:160',
]),
SEO Preview
Integrate with a package like spatie/laravel-honeypot to preview SEO changes in real-time:
public static function table(Table $table): Table
{
return $table->columns([
// ...
Tables\Columns\TextColumn::make('seo_preview')
->view('filament-seo::preview', ['seo' => fn ($record) => $record->seo]),
]);
}
Localization Use Filament’s localization features to support multi-language SEO:
SEOFields::make()->translatable([
'title', 'description', 'keywords',
]);
Laravel 13 Features Leverage new Laravel 13 features like app models or improved routing for enhanced SEO management:
// Example: Using app models for cleaner SEO model binding
public function seo()
{
return $this->morphOne(app(Seo::class), 'model');
}
How can I help you explore Laravel packages today?