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

Media Bundle Laravel Package

2lenet/media-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require 2lenet/media-bundle
    
  2. Enable the Bundle Add to config/bundles.php:

    return [
        // ...
        Lle\MediaBundle\LleMediaBundle::class => ['all' => true],
    ];
    
  3. Configure Routing Add to config/routes.yaml:

    media_routing:
        resource: "@LleMediaBundle/Resources/config/routing.yaml"
    
  4. Enable Doctrine Extensions Ensure gedmo/doctrine-extensions is installed and configured in config/packages/doctrine.yaml:

    gedmo_tree:
        types:
            tree: Lle\MediaBundle\Doctrine\Extensions\TreeType
    
  5. First Use Case Create a media entity (e.g., MediaItem) with a tree structure:

    use Lle\MediaBundle\Entity\MediaInterface;
    use Gedmo\Mapping\Annotation as Gedmo;
    
    #[Gedmo\Tree(type: 'nested')]
    class MediaItem implements MediaInterface
    {
        // ...
    }
    

Implementation Patterns

Core Workflows

  1. Hierarchical Media Management Use the TreeType for nested media structures (e.g., folders/files):

    $parent = $mediaRepository->findOneBy(['name' => 'Parent']);
    $child = new MediaItem();
    $child->setParent($parent);
    $em->persist($child);
    
  2. Route Generation Leverage the bundle’s routes for CRUD operations:

    $url = $this->router->generate('lle_media_item_edit', ['id' => $media->getId()]);
    
  3. Asset Handling Extend MediaInterface to add custom fields (e.g., path, mimeType):

    class CustomMediaItem extends MediaItem
    {
        #[ORM\Column(type: 'string')]
        private string $customField;
    }
    
  4. Event Listeners Hook into lifecycle events (e.g., prePersist) for validation:

    $media->addEventListener(MediaEvents::PRE_PERSIST, function (MediaItem $media) {
        if (empty($media->getName())) {
            throw new \RuntimeException('Media name is required.');
        }
    });
    

Gotchas and Tips

Pitfalls

  1. Gedmo Tree Misconfiguration

    • Ensure gedmo/tree is installed and enabled in doctrine.yaml.
    • Debug with php bin/console doctrine:schema:validate if tree queries fail.
  2. Route Conflicts

    • Prefix routes in routing.yaml to avoid clashes with existing routes:
      lle_media_item:
          resource: "@LleMediaBundle/Resources/config/routing/item.yaml"
          prefix: /media
      
  3. Missing MediaInterface

    • All entities must implement MediaInterface; abstract classes won’t work.

Debugging

  • Tree Queries: Use TreeRepository for debugging:
    $children = $mediaRepository->findBy(['parent' => $media]);
    
  • Logs: Enable debug mode (APP_DEBUG=true) to inspect route generation.

Extension Points

  1. Custom Fields Add fields to MediaInterface and update the bundle’s MediaType:

    #[ORM\Column(type: 'json')]
    private array $metadata;
    
  2. Override Templates Extend the bundle’s Twig templates by copying them to templates/LleMediaBundle/ and modifying.

  3. API Integration Use Symfony’s Serializer to expose media as JSON:

    $serializer->serialize($media, 'json', ['groups' => ['media']]);
    
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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php