Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Seo Laravel Package

ralphjsmit/laravel-seo

Out-of-the-box SEO for Laravel models: automatically generates title, meta, OpenGraph, Twitter, structured data, robots, alternates and favicon tags. Store per-model SEO or derive it dynamically, then render everything with a simple seo()->for($model) call.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Seamless Laravel Integration: Designed natively for Laravel, leveraging Eloquent models, Blade directives, and Laravel’s service container. Minimal boilerplate for basic SEO implementation.
    • Modular & Extensible: Follows a Spatie-like pattern (familiar to Laravel devs), with clear separation between static configs, dynamic model data, and runtime overrides.
    • Comprehensive Coverage: Handles meta tags, OpenGraph, Twitter Cards, structured data (JSON-LD), canonical links, and robots directives—reducing the need for multiple packages.
    • Dynamic Data Fetching: Supports runtime SEO generation via getDynamicSEOData(), enabling real-time updates without manual DB writes.
    • Structured Data Support: Built-in JSON-LD generation for schema.org (Articles, FAQs, Breadcrumbs, etc.), critical for modern SEO.
  • Cons:

    • Tight Coupling to Eloquent: Requires models to use HasSEO trait for full functionality, which may not fit headless or API-first architectures.
    • Blade Dependency: Core functionality relies on {!! seo() !!} directives, limiting use in non-Blade contexts (e.g., API responses, SSR frameworks like Inertia).
    • Configuration Complexity: Defaults (e.g., robots, title.suffix) require upfront setup, which may not align with all project needs.
    • No Built-in Sitemap Generation: While it supports sitemap paths, it doesn’t generate them (requires spatie/laravel-sitemap separately).

Integration Feasibility

  • Low Effort for Basic Use: Install, publish migrations/config, and add {!! seo() !!} to layouts. Works out-of-the-box for simple sites.
  • Medium Effort for Dynamic SEO: Requires implementing getDynamicSEOData() in models or manually updating associated SEO models.
  • High Effort for Advanced Use: Custom schema types, multi-lingual support (via AlternateTag), or non-Eloquent data sources demand additional logic.

Technical Risk

  • Migration Overhead: Publishing migrations/config and setting up relationships (HasSEO) adds initial complexity.
  • Performance Impact:
    • Dynamic SEO data fetching (getDynamicSEOData()) may introduce runtime overhead if not optimized (e.g., lazy-loading model properties).
    • Structured data generation (JSON-LD) adds payload size to responses.
  • Blade Limitation: Non-Blade templates (e.g., API responses, Inertia) require manual tag generation or middleware workarounds.
  • Schema Validation: Custom schema types (e.g., SchemaCollection) require familiarity with JSON-LD to avoid misconfiguration.
  • Dependency on secure_url(): Favicon/image paths must be publicly accessible, which may conflict with storage setups (e.g., S3).

Key Questions

  1. Architecture Alignment:
    • Does your app use Eloquent models? If not, how will you integrate SEO data (e.g., via middleware, services)?
    • Are you using Blade templates, or do you need SEO tags in API responses/SSR frameworks?
  2. Dynamic vs. Static SEO:
    • Will most SEO data be static (stored in SEO models) or dynamic (generated via getDynamicSEOData())?
    • How will you handle edge cases (e.g., missing author, image in dynamic data)?
  3. Performance:
    • Will dynamic SEO data fetching impact page load times? Consider caching strategies.
    • Is JSON-LD structured data critical, or can you defer it to a separate endpoint?
  4. Multi-Lingual Support:
    • Do you need AlternateTag for hreflang? If so, how will you manage language-specific SEO data?
  5. Testing:
    • How will you test SEO tag generation (e.g., unit tests for getDynamicSEOData(), integration tests for Blade rendering)?
  6. Maintenance:
    • Who will manage SEO configurations (e.g., title.suffix, robots.default) as requirements evolve?
    • How will you handle breaking changes (e.g., new Laravel versions, package updates)?

Integration Approach

Stack Fit

  • Best Fit For:
    • Traditional Laravel apps with Eloquent models and Blade templates.
    • Projects prioritizing out-of-the-box SEO with minimal manual tag management.
    • Teams comfortable with Spatie-like package patterns.
  • Less Ideal For:
    • Headless APIs or non-Blade frontend frameworks (e.g., React, Vue with direct API calls).
    • Apps requiring fine-grained control over SEO at the route/middleware level (e.g., per-route SEO overrides).
    • Projects using non-Eloquent data sources (e.g., GraphQL, raw arrays).

Migration Path

  1. Assessment Phase:
    • Audit existing SEO implementation (if any) to identify gaps (e.g., missing OpenGraph, structured data).
    • Decide on dynamic vs. static SEO strategy (e.g., "All blog posts use getDynamicSEOData(); static pages use SEO models").
  2. Installation:
    composer require ralphjsmit/laravel-seo
    php artisan vendor:publish --tag="seo-migrations"
    php artisan vendor:publish --tag="seo-config"
    php artisan migrate
    
  3. Configuration:
    • Update config/seo.php with site-wide defaults (e.g., site_name, title.suffix, robots).
    • Configure favicon, sitemap, and fallback values (e.g., description.fallback).
  4. Model Integration:
    • Add HasSEO trait to relevant models (e.g., Post, Page).
    • Implement getDynamicSEOData() for models needing runtime SEO generation.
  5. Template Integration:
    • Replace manual meta tags with {!! seo()->for($model) !!} in Blade layouts.
    • For dynamic routes (e.g., no model), use {!! seo($SEOData) !!} with manually constructed SEOData.
  6. Structured Data:
    • Define custom schemas (e.g., Article, FAQPage) using SchemaCollection in getDynamicSEOData().
  7. Testing:
    • Write tests for getDynamicSEOData() logic.
    • Verify Blade rendering with tools like Rich Results Test.

Compatibility

  • Laravel Versions: Tested with Laravel 9+ (check composer.json for exact compatibility).
  • PHP Versions: Requires PHP 8.0+.
  • Dependencies:
    • Conflicts: None major, but ensure no other packages override meta tags (e.g., spatie/laravel-head).
    • Complements: Works well with spatie/laravel-sitemap, spatie/laravel-media-library, and inertiajs/inertia-laravel.
  • Database: Requires a seos table (published via migrations). Supports MySQL, PostgreSQL, SQLite.

Sequencing

  1. Phase 1: Core Setup (1–2 days):
    • Install, configure, and test basic SEO generation (title, description, OpenGraph).
    • Integrate with 1–2 critical models (e.g., Post).
  2. Phase 2: Dynamic SEO (1–3 days):
    • Implement getDynamicSEOData() for models needing runtime generation.
    • Test edge cases (e.g., missing image, fallback values).
  3. Phase 3: Advanced Features (3–5 days):
    • Add structured data (JSON-LD) for key pages (e.g., blog posts, FAQs).
    • Implement multi-lingual support (AlternateTag).
    • Configure robots directives and canonical links.
  4. Phase 4: Optimization (Ongoing):
    • Cache dynamic SEO data where possible.
    • Monitor performance impact of JSON-LD.
    • Set up monitoring for SEO tag rendering (e.g., failed image paths).

Operational Impact

Maintenance

  • Pros:
    • Centralized Configuration: SEO defaults live in config/seo.php, making updates easy.
    • Model-Driven: Changes to SEO data often align with model updates (e.g., Post title changes auto-update SEO).
    • Extensible API: Custom logic can be added via SEOManager::SEODataTransformer() or middleware.
  • Cons:
    • Migration Risk: Schema changes (e.g., adding published_time to SEO model) require migrations.
    • Dynamic Logic Maintenance: getDynamicSEOData() methods may need updates if model structures change.
    • Blade Dependency: Template changes (e.g., switching from Blade to another templating engine) may break SEO rendering.

Support

  • Debugging:
    • Use dd(seo()->for($model)->toArray()) to inspect generated tags.
    • Check Laravel logs for missing file paths (e.g., image in SEOData).
    • Validate structured data with [Google’s Rich Results Test](https://search.google.com/test/
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport