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

Meta Laravel Package

chamber-orchestra/meta

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require chamber-orchestra/meta
    

    Add the bundle to config/bundles.php (Symfony) or register the service provider in config/app.php (Laravel via Symfony bridge):

    ChamberOrchestra\MetaBundle\MetaBundle::class => ['all' => true],
    
  2. Doctrine Trait Integration Add the MetaTrait to your entity:

    use ChamberOrchestra\MetaBundle\Model\MetaTrait;
    
    class Page extends AbstractEntity
    {
        use MetaTrait;
        // ...
    }
    
  3. Database Migration Run migrations to add the meta fields (meta_title, meta_description, etc.) to your table.

  4. First Use Case Define meta fields in your entity:

    $page = new Page();
    $page->setMetaTitle('My SEO Title');
    $page->setMetaDescription('Optimized description for search engines');
    $page->setMetaKeywords(['keyword1', 'keyword2']);
    $page->setMetaRobots('index,follow');
    $page->setMetaOpenGraphImage('/path/to/image.jpg');
    

Implementation Patterns

Common Workflows

  1. Dynamic Meta Generation Override getMetaTitle() in your entity to generate dynamic titles:

    public function getMetaTitle(): ?string
    {
        return "Default: {$this->title} | {$this->getSiteName()}";
    }
    
  2. Form Integration (Symfony) Use MetaType in your form builder:

    $builder->add('meta', MetaType::class, [
        'mapped' => false,
        'fields' => ['title', 'description', 'keywords', 'robots', 'og_image'],
    ]);
    
  3. Laravel-Specific Twist Create a MetaService to centralize meta logic:

    class MetaService {
        public function generateMetaTags(Page $page): array
        {
            return [
                'title' => $page->getMetaTitle(),
                'description' => $page->getMetaDescription(),
                // ...
            ];
        }
    }
    
  4. Repository Filtering Filter entities by meta fields in Doctrine queries:

    $pages = $repo->findBy(['meta_title' => '%SEO%']);
    
  5. Twig Integration (Symfony) Access meta fields in templates:

    <title>{{ page.metaTitle }}</title>
    <meta name="description" content="{{ page.metaDescription }}">
    

Gotchas and Tips

Pitfalls

  1. Missing Trait Initialization Ensure MetaTrait is used after TimestampableTrait (if applicable) to avoid field conflicts.

  2. Doctrine Lifecycle Hooks Override prePersist()/preUpdate() if you need to sanitize meta fields:

    public function prePersist()
    {
        $this->setMetaKeywords(array_map('strtolower', $this->getMetaKeywords()));
    }
    
  3. Open Graph Image Paths Store absolute URLs (not relative paths) for metaOpenGraphImage to avoid 404s.

  4. Robots Meta Quirks Default value is index,follow. Explicitly set to noindex if needed:

    $page->setMetaRobots('noindex');
    

Debugging Tips

  • Check Database Schema Verify fields exist via:

    php bin/console doctrine:schema:validate
    
  • Log Meta Fields Add a debug method to your entity:

    public function debugMeta(): string
    {
        return json_encode([
            'title' => $this->getMetaTitle(),
            'description' => $this->getMetaDescription(),
            // ...
        ]);
    }
    

Extension Points

  1. Custom Meta Fields Extend the trait to add fields (e.g., twitter_card):

    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Column(nullable: true)]
    private ?string $metaTwitterCard = null;
    
    public function getMetaTwitterCard(): ?string { return $this->metaTwitterCard; }
    public function setMetaTwitterCard(?string $card): self { $this->metaTwitterCard = $card; return $this; }
    
  2. Validation Add Symfony Validator constraints:

    use Symfony\Component\Validator\Constraints as Assert;
    
    #[Assert\Length(max: 60)]
    private ?string $metaTitle = null;
    
  3. Event Listeners Trigger events on meta changes (e.g., log updates):

    // config/services.yaml
    ChamberOrchestra\MetaBundle\EventListener\MetaUpdateListener:
        tags:
            - { name: doctrine.event_listener, event: preUpdate }
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
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