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

Blog Bundle Laravel Package

dywee/blog-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Run composer require dywee/blog-bundle in your Laravel project (note: this is a Symfony bundle, so ensure compatibility with Laravel via Symfony Bridge or use in a Symfony project). Add the bundle to config/app.php under providers:

    Dywee\BlogBundle\DyweeBlogBundle::class,
    
  2. Routing Add the routing to routes/web.php:

    use Dywee\BlogBundle\Resources\config\routing.yml;
    $loader = new \Symfony\Component\Config\Loader\LoaderInterface();
    $loader->load(__DIR__.'/vendor/dywee/blog-bundle/Resources/config/routing.yml');
    

    Note: Laravel’s native YAML routing support is limited; use a Symfony-compatible router or convert to PHP routes.

  3. First Use Case Create a blog post via the admin interface (if DyweeCoreBundle is integrated) or manually via:

    use Dywee\BlogBundle\Entity\Post;
    
    $post = new Post();
    $post->setTitle('Hello World');
    $post->setContent('First blog post!');
    $em = $this->getDoctrine()->getManager();
    $em->persist($post);
    $em->flush();
    

Implementation Patterns

Core Workflows

  1. Entity Management

    • Posts: Extend Dywee\BlogBundle\Entity\Post for custom fields (e.g., slug, publishedAt).
      namespace App\Entity;
      use Dywee\BlogBundle\Entity\Post as BasePost;
      
      class Post extends BasePost {
          // Custom fields/methods
      }
      
    • Categories/Tags: Use Dywee\BlogBundle\Entity\Category and Tag entities for taxonomy.
  2. Admin Integration

    • Leverage DyweeCoreBundle for CRUD interfaces (if available). Example:
      // Configure admin routes in DyweeCoreBundle
      $builder->root()->add('posts', 'dywee_blog_post_crud');
      
  3. Frontend Display

    • Fetch posts via repository:
      $posts = $this->getDoctrine()->getRepository(Post::class)->findBy(['published' => true]);
      
    • Use Twig templates (if Symfony) or Blade (Laravel) with:
      {% for post in posts %}
          <h2>{{ post.title }}</h2>
          <p>{{ post.content|truncate(200) }}</p>
      {% endfor %}
      
  4. API Endpoints

    • Expose posts via API routes:
      Route::get('/api/posts', [PostController::class, 'index']);
      
    • Serialize entities with Serializer (Symfony) or Laravel’s Resource classes.

Integration Tips

  • Doctrine ORM: Ensure your config/packages/doctrine.yaml includes:
    orm:
        mappings:
            dywee_blog:
                type: attribute
                dir: "%kernel.project_dir%/vendor/dywee/blog-bundle/Entity"
                prefix: "Dywee\BlogBundle\Entity"
                alias: DyweeBlog
    
  • Laravel-Specific: Use SymfonyBridge to integrate Symfony bundles:
    composer require symfony/bridge
    
    Then register the bundle in config/app.php.

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel Compatibility

    • Issue: The bundle assumes Symfony’s ContainerInterface and Twig. In Laravel:
      • Replace ContainerAware traits with Laravel’s Container binding.
      • Mock Twig templates with Blade or use symfony/twig-bridge.
    • Fix: Override service definitions in config/services.yaml (Symfony) or Laravel’s AppServiceProvider.
  2. Routing Conflicts

    • Issue: Prefix collisions if dywee_blog routes overlap with Laravel’s default routes.
    • Fix: Explicitly prefix routes in routes/web.php:
      Route::prefix('blog')->group(function () {
          // Include dywee_blog routes here
      });
      
  3. Missing Documentation

    • Issue: The README is incomplete. Key gaps:
      • Entity structure (e.g., Post fields).
      • Admin panel setup (if DyweeCoreBundle is required).
    • Fix: Inspect Entity/ and Resources/config/ directories for clues. Example:
      // Check Post entity for available methods
      $post->setPublished(true); // Hypothetical method
      
  4. Doctrine Events

    • Issue: Custom post lifecycle events (e.g., prePersist) may not be wired.
    • Fix: Subscribe to events in a listener:
      namespace App\EventListener;
      use Dywee\BlogBundle\Entity\Post;
      use Doctrine\ORM\Event\LifecycleEventArgs;
      
      class PostListener {
          public function prePersist(Post $post, LifecycleEventArgs $args) {
              $post->setSlug(\Str::slug($post->getTitle()));
          }
      }
      
      Register in config/services.yaml:
      Dywee\BlogBundle\Entity\Post:
          tags:
              - { name: doctrine.event_listener, event: prePersist }
      

Debugging Tips

  1. Check Entity Metadata Use Doctrine’s metadata tool to validate entities:

    php bin/console doctrine:metadata:info --entity="Dywee\BlogBundle\Entity\Post"
    
  2. Enable Debug Mode In Symfony, set APP_DEBUG=true in .env. In Laravel, use:

    $this->app->setDebugMode(true);
    
  3. Log SQL Queries Add to config/packages/doctrine.yaml:

    dbal:
        logging: true
        logging:
            db: "%kernel.logs_dir%/doctrine.log"
    

Extension Points

  1. Custom Fields Extend the Post entity and update migrations:

    namespace App\Entity;
    use Dywee\BlogBundle\Entity\Post as BasePost;
    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity]
    class Post extends BasePost {
        #[ORM\Column(type: 'string', length: 255)]
        private $customField;
    }
    
  2. Override Templates Copy Resources/views/ from the bundle to your project’s templates/ directory to customize Twig templates.

  3. Add Validation Use Symfony’s validator or Laravel’s validation rules:

    use Symfony\Component\Validator\Constraints as Assert;
    
    #[ORM\Entity]
    class Post extends BasePost {
        #[Assert\NotBlank]
        private $title;
    }
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui