Adding SEO fields to your Filament resources in 5 minutes
High agreement — the answer is well-supported across models.
Models agree on
- ✓Adding SEO fields to Filament resources enhances search engine optimization
- ✓Common SEO fields include `title`, `description`, and `keywords`
- ✓Dynamic generation of `<title>` and `<meta>` tags in views is recommended
- ✓Using a dedicated section or package like `artizan/laravel-seo` can streamline the process
Adding SEO fields to your Filament resources is a quick and effective way to enhance your Laravel application's search engine optimization. Here's a streamlined approach to achieve this in just 5 minutes:
Step 1: Prepare Your Database
Start by adding the necessary SEO fields to your resource's table. Create a migration:
bash php artisan make:migration add_seo_fields_to_resource_table --table=resource_table
In the migration file, define the SEO columns:
php Schema::table('resource_table', function (Blueprint $table) { $table->string('meta_title')->nullable(); $table->text('meta_description')->nullable(); $table->string('meta_keywords')->nullable(); });
Run the migration:
bash php artisan migrate
Step 2: Add SEO Fields to Your Filament Resource
In your Filament resource class, register the SEO fields. Use Text, Textarea, and TagsInput for title, description, and keywords respectively:
php protected function getFields(): array { return [ // Other existing fields...
Text::make('Meta Title')->column('meta_title'),
Textarea::make('Meta Description')->column('meta_description'),
TagsInput::make('Meta Keywords')->column('meta_keywords'),
];
}
Optionally, you can organize these fields into a dedicated section:
php Forms\Components\Section::make('SEO') ->schema([ Forms\Components\TextInput::make('seo.title')->label('Title'), Forms\Components\Textarea::make('seo.description')->label('Description'), Forms\Components\TextInput::make('seo.keywords')->label('Keywords'), ]),
Step 3: Utilize SEO Data in Your Application
To maximize the impact of your SEO fields, dynamically generate <title> and <meta> tags in your views:
php
<title>{{ $resource->meta_title ?: 'Default Title' }}</title> <meta name="description" content="{{ $resource->meta_description ?: 'Default Description' }}"> <meta name="keywords" content="{{ $resource->meta_keywords ?: 'default, keywords' }}">For a more advanced approach, consider using a package like artizan/laravel-seo. Install it via Composer:
bash composer require artizan/laravel-seo
Publish the package's configuration and migrations:
bash php artisan vendor:publish --provider="Artizan\LaravelSeo\LaravelSeoServiceProvider" php artisan migrate
Create a HasSeo trait to handle SEO fields:
php namespace App\Traits;
use Artizan\LaravelSeo\Models\SeoMeta;
trait HasSeo { public static function bootHasSeo() { static::created(function ($model) { $model->seo()->save(new SeoMeta()); });
static::deleted(function ($model) {
$model->seo()->delete();
});
}
public function seo()
{
return $this->morphOne(SeoMeta::class, 'seoable');
}
}
Use this trait in your model:
php namespace App\Models;
use App\Traits\HasSeo; use Illuminate\Database\Eloquent\Model;
class Page extends Model { use HasSeo;
// ...
}
With these steps, you can quickly add and manage SEO fields in your Filament resources, ensuring your application is optimized for search engines.
Follow-ups
You just saw open-source models answer
Want GPT-5, Claude, Gemini & more on the same question?
Sign in free to run any question against frontier models — side by side, same synthesis, honest comparison.