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

Seo Bundle Laravel Package

bigfoot/seo-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require bigfoot/seo-bundle
    

    Add the bundle to config/bundles.php under C2IS\BigFoot\SeoBundle\BigFootSeoBundle.

  2. Database Migration: Run migrations to create the required tables (check src/Resources/migrations/ for schema). If using Symfony’s Doctrine migrations, ensure they’re imported.

  3. Backend Access: Navigate to /admin/seo in your backend to access the SEO management UI. No additional configuration is needed for basic functionality.

First Use Case

Dynamic Meta Tags for a Route:

  • Define a route (e.g., hotel_show) in your routes.yaml or controller.
  • In the Seo Parameters section, associate a parameter (e.g., hotel_name) with the route.
  • In the Seo section, create an entry for the route with a title like Hotel ::hotel_name:.
  • The bundle replaces ::hotel_name: with the actual value (e.g., "Grand Hotel") when rendering the page.

Implementation Patterns

Workflow Integration

  1. Route-Based SEO Management:

    • Use the bundle’s admin panel to manage SEO metadata per route. Avoid hardcoding meta tags in controllers/templates.
    • Example: For a blog post route (/blog/{slug}), create a parameter post_title and use it in the SEO title field.
  2. Parameter Binding:

    • Parameters are tied to routes via the admin panel. Ensure your routes are registered before SEO rules are applied.
    • Example: For a dynamic product page, bind product_name and product_price to the route product_show.
  3. Twig Integration:

    • The bundle automatically injects meta tags into the <head> section. Extend the base template (base.html.twig) to include:
      <title>{{ app.seo.title }}</title>
      <meta name="description" content="{{ app.seo.description }}">
      <meta name="keywords" content="{{ app.seo.keywords }}">
      
  4. Fallback Logic:

    • Provide default meta tags in your config/packages/bigfoot_seo.yaml:
      default:
          title: "Default Title"
          description: "Default description for pages without SEO rules."
      
  5. API/Non-HTML Responses:

    • Disable SEO processing for API routes by adding a tag to your route:
      _seo: false
      

Advanced Patterns

  • Parameter Validation:

    • Use Symfony’s validator constraints to validate parameter values (e.g., NotBlank, Length) before rendering SEO tags.
    • Example: Ensure hotel_name is not empty in the hotel_show route.
  • Multi-Language Support:

    • Store SEO metadata per locale using Doctrine’s translations or separate entries for each locale in the admin panel.
  • Event Listeners:

    • Extend functionality by listening to the bigfoot.seo.pre_render event to modify metadata dynamically:
      // src/EventListener/SeoListener.php
      public function onPreRender(SeoEvent $event) {
          if ($event->getRoute() === 'homepage') {
              $event->setTitle('Welcome to ' . config('app.name'));
          }
      }
      
      Register the listener in services.yaml:
      services:
          App\EventListener\SeoListener:
              tags:
                  - { name: kernel.event_listener, event: bigfoot.seo.pre_render, method: onPreRender }
      

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies:

    • The bundle was last updated in 2014 and may not support newer Symfony/Laravel versions (or PHP frameworks at all—this is a Symfony bundle). Test thoroughly in a staging environment.
    • Workaround: Fork the repository and update dependencies manually (e.g., Symfony 5/6 compatibility).
  2. Route Name Mismatches:

    • SEO rules are tied to route names, not paths. Ensure your route names in routes.yaml match those used in the admin panel.
    • Debug Tip: Use dump(app->get('router')->getRouteCollection()->getNameConverter()) to list all route names.
  3. Parameter Placeholder Syntax:

    • The placeholder syntax (::parameter_name:) is case-sensitive and must match exactly what’s defined in the admin panel.
    • Fix: Double-check spelling in both the SEO entry and parameter definition.
  4. Caching Issues:

    • If meta tags aren’t updating, clear the cache:
      php bin/console cache:clear
      
    • For production, use cache:pool:clear for specific pools (e.g., seo_cache).
  5. Missing Admin Route:

    • The /admin/seo route may not appear if the bundle isn’t properly registered in bundles.php or if Symfony’s security firewall blocks it.
    • Check: Verify the seo route exists via php bin/console debug:router | grep seo.

Debugging Tips

  • Log SEO Events: Add a subscriber to log SEO rendering:

    public function onPostRender(SeoEvent $event) {
        \Log::debug('SEO Rendered', [
            'route' => $event->getRoute(),
            'title' => $event->getTitle(),
            'description' => $event->getDescription(),
        ]);
    }
    
  • Inspect Database: Check the seo_parameter and seo tables directly to verify entries:

    SELECT * FROM seo_parameter WHERE route_name = 'hotel_show';
    SELECT * FROM seo WHERE route_name = 'hotel_show';
    

Extension Points

  1. Custom Parameter Sources: Override the parameter resolver to fetch values from non-admin sources (e.g., API calls):

    // src/Resolver/CustomParameterResolver.php
    public function resolve($parameterName, Route $route) {
        if ($parameterName === 'api_data') {
            return $this->fetchFromExternalApi();
        }
        return parent::resolve($parameterName, $route);
    }
    

    Register as a service with the tag bigfoot.seo.parameter_resolver.

  2. Additional Meta Tags: Extend the bundle’s SeoManager to support custom meta tags (e.g., OpenGraph):

    // src/Service/ExtendedSeoManager.php
    public function getOpenGraphTags() {
        return $this->getParameter('og_title') ?: [];
    }
    

    Update Twig templates to render these new tags.

  3. Bulk SEO Imports: Use Doctrine’s EntityManager to bulk-insert SEO rules via a command:

    // src/Command/ImportSeoCommand.php
    $seoRepository->save(new Seo([
        'routeName' => 'product_show',
        'title' => 'Product ::product_name:',
        'description' => 'Details for ::product_name:',
    ]), true);
    
  4. Override Twig Variables: Extend the bundle’s Twig environment to add custom variables:

    # config/packages/twig.yaml
    twig:
        globals:
            app_seo_extended: '@bigfoot_seo.manager'
    

    Access in Twig: {{ app_seo_extended.getCustomTag('canonical_url') }}.


### Configuration Quirks
- **Parameter Order**:
  If multiple parameters share the same name across routes, the **last defined** in the database takes precedence.

- **Empty Parameters**:
  The bundle doesn’t validate empty parameters by default. Add a validator to the `SeoParameter` entity to enforce non-empty values.

- **Route Collection Refresh**:
  After adding new routes, refresh the route collection:
  ```bash
  php bin/console debug:router
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor