/laravel-agent:seo:setup
Setup SEO infrastructure with sitemaps, meta tags, and structured data
Overview
The /seo:setup command configures comprehensive SEO infrastructure for your Laravel application. It installs and configures popular packages for XML sitemap generation, dynamic meta tags, Open Graph support, Twitter Cards, and model-based SEO data management with Filament integration.
Usage
/laravel-agent:seo:setup [--sitemap] [--meta] [--opengraph] [--schema] [--all]
Examples
# Interactive setup with component selection
/laravel-agent:seo:setup
# Setup just sitemap generation
/laravel-agent:seo:setup --sitemap
# Setup meta tags with artesaos/seotools
/laravel-agent:seo:setup --meta
# Setup complete SEO infrastructure
/laravel-agent:seo:setup --all
SEO Components
The command can install and configure three main SEO components:
| Component | Package | Purpose |
|---|---|---|
| Sitemap Generation | spatie/laravel-sitemap |
Automatic XML sitemap generation with model support |
| Meta Tags | artesaos/seotools |
Dynamic meta tags, Open Graph, Twitter Cards |
| Model-Based SEO | ralphjsmit/laravel-seo |
Store SEO data per model with Filament integration |
Sitemap Generation Setup
When you select sitemap generation, the command installs spatie/laravel-sitemap and creates a custom artisan command for generating XML sitemaps.
Generated Sitemap Command
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Models\Post;
use App\Models\Product;
use Illuminate\Console\Command;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url;
final class GenerateSitemapCommand extends Command
{
protected $signature = 'sitemap:generate';
protected $description = 'Generate XML sitemap';
public function handle(): int
{
$sitemap = Sitemap::create();
// Static pages
$sitemap->add(Url::create('/')->setPriority(1.0));
$sitemap->add(Url::create('/about')->setPriority(0.8));
// Dynamic content
Post::published()->each(fn ($post) =>
$sitemap->add(Url::create(route('posts.show', $post))
->setLastModificationDate($post->updated_at)
->setPriority(0.9))
);
$sitemap->writeToFile(public_path('sitemap.xml'));
$this->info('Sitemap generated!');
return self::SUCCESS;
}
}
Scheduling Sitemap Generation
The command can automatically schedule sitemap generation in your app/Console/Kernel.php:
$schedule->command('sitemap:generate')->daily();
Meta Tags Setup
The meta tags component uses artesaos/seotools to provide dynamic meta tags, Open Graph support, and Twitter Cards.
Configuration
The command publishes and configures config/seotools.php with sensible defaults:
return [
'meta' => [
'defaults' => [
'title' => env('APP_NAME'),
'description' => 'Your site description',
'keywords' => ['laravel', 'application'],
'canonical' => null,
'robots' => 'index, follow',
],
],
'opengraph' => [
'defaults' => [
'title' => env('APP_NAME'),
'description' => 'Your site description',
'type' => 'website',
'site_name' => env('APP_NAME'),
],
],
'twitter' => [
'defaults' => [
'card' => 'summary_large_image',
'site' => '@yourhandle',
],
],
];
Controller Usage
Use the SEOTools facade in your controllers to set dynamic meta tags:
use Artesaos\SEOTools\Facades\SEOTools;
public function show(Post $post)
{
SEOTools::setTitle($post->title);
SEOTools::setDescription($post->excerpt);
SEOTools::opengraph()->setUrl(route('posts.show', $post));
SEOTools::opengraph()->addImage($post->featured_image);
SEOTools::twitter()->setImage($post->featured_image);
SEOTools::jsonLd()->addImage($post->featured_image);
return view('posts.show', compact('post'));
}
Blade Integration
<head>
{!! SEO::generate() !!}
</head>
Model-Based SEO Setup
The model-based SEO component uses ralphjsmit/laravel-seo to store SEO data directly in your database with a polymorphic relationship. It includes Filament panel integration for easy management.
Adding SEO to Models
The command adds the HasSEO trait to your selected models:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use RalphJSmit\Laravel\SEO\Support\HasSEO;
final class Post extends Model
{
use HasSEO;
}
Creating SEO Data in Controllers
public function store(Request $request)
{
$post = Post::create($request->validated());
$post->seo()->update([
'title' => $request->seo_title,
'description' => $request->seo_description,
'image' => $request->seo_image,
]);
return redirect()->route('posts.show', $post);
}
Blade Component
<head>
<x-seo::meta />
</head>
Filament Integration
The package includes a Filament form component for easy SEO management:
use RalphJSmit\Laravel\SEO\Support\SEOData;
use RalphJSmit\Filament\SEO\SEO;
public static function form(Form $form): Form
{
return $form->schema([
TextInput::make('title'),
RichEditor::make('content'),
// SEO Section
SEO::make(),
]);
}
Interactive Prompts
When run without flags, the command presents interactive prompts:
1. Component Selection
- Sitemap (spatie/laravel-sitemap)
- Meta Tags (artesaos/seotools)
- Model SEO (ralphjsmit/laravel-seo)
- All components
2. Sitemap Generation Method
- Crawl-based (automatic URL discovery)
- Model-based (from Eloquent models)
- Hybrid (static + dynamic)
3. Schedule Configuration
- Daily (recommended)
- Hourly
- Weekly
- Manual only
4. Model Selection
Select which existing models should have SEO data management.
What Gets Created
| Component | Location | Description |
|---|---|---|
| Sitemap Command | app/Console/Commands/GenerateSitemapCommand.php |
Artisan command for sitemap generation |
| SEO Config | config/seotools.php |
Published configuration for meta tags |
| SEO Migration | database/migrations/create_seo_table.php |
Database table for model-based SEO |
| Model Updates | app/Models/*.php |
HasSEO trait added to selected models |
| Layout Updates | resources/views/layouts/app.blade.php |
SEO tags integration |
Generated Commands
After setup, you'll have access to these commands:
# Generate sitemap manually
php artisan sitemap:generate
# Run migrations for SEO tables
php artisan migrate
Example Output
The command provides a comprehensive summary after completion:
## SEO Infrastructure Setup
### Packages Installed
- spatie/laravel-sitemap
- artesaos/seotools
- ralphjsmit/laravel-seo
### Files Created
- app/Console/Commands/GenerateSitemapCommand.php
- config/seotools.php (published)
### Files Modified
- app/Models/Post.php (HasSEO trait)
- app/Models/Page.php (HasSEO trait)
- resources/views/layouts/app.blade.php (SEO tags)
### Database
- Migration: create_seo_table
### Schedule
- Sitemap: Daily at midnight
Next Steps
After running the setup command, follow these steps to complete your SEO configuration:
- Run
php artisan migrateto create the SEO tables - Run
php artisan sitemap:generateto create your initial sitemap - Add
Sitemap: https://yoursite.com/sitemap.xmlto yourrobots.txt - Submit your sitemap to Google Search Console
- Configure default SEO values in
config/seotools.php - Customize the sitemap command to include your specific models and routes
- Add SEO fields to your Filament panels using the SEO component
Best Practices
- Use descriptive titles - Keep titles under 60 characters for optimal display
- Write compelling descriptions - Meta descriptions should be 150-160 characters
- Generate sitemaps regularly - Schedule daily generation for frequently updated content
- Add images to Open Graph - Use high-quality featured images (1200x630px recommended)
- Implement structured data - Use JSON-LD for rich search results
- Monitor performance - Use Google Search Console to track SEO metrics
Related Commands
- /laravel-agent:model:make - Create models that can use SEO traits
- /laravel-agent:filament:setup - Setup Filament for SEO management