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

Easy Blog Laravel Package

bytes-commerce/easy-blog

Drop-in Symfony blog bundle with EasyAdmin CRUD. Manage posts, hierarchical categories and FAQs, plus built-in SEO fields. Ships with responsive Twig templates and integrates with your app’s User entity for post authors.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup for First Use

  1. Installation:

    composer require bytes-commerce/easy-blog
    

    Add to config/bundles.php and configure easy_blog.yaml.

  2. First Post Creation:

    • Use EasyAdmin CRUD to create a Post entity via the dashboard.
    • Assign a Category (create one if needed) and an Author (your User entity).
    • Save and publish the post.
  3. Viewing Content:

    • Access the post via the generated route: /beitraege/{slug} (e.g., /beitraege/my-first-post).
    • Use the blog.post Twig template to render it in your frontend.

Where to Look First

  • EasyAdmin Dashboard: Navigate to Posts and Categories CRUD interfaces.
  • Templates: Override templates/bundles/EasyBlog/blog/post/view.html.twig for custom post rendering.
  • Routes: Check blog.post and blog.category.all-posts for frontend integration.

Implementation Patterns

Common Workflows

  1. Post Management:

    • Create/Edit: Use EasyAdmin’s CRUD for authors.
    • Programmatic Creation:
      $post = new Post();
      $post->setTitle('Hello World')
           ->setSlug('hello-world')
           ->setContent('...')
           ->setAuthor($user);
      $entityManager->persist($post);
      $entityManager->flush();
      
  2. Category Hierarchy:

    • Set parent-child relationships via EasyAdmin or programmatically:
      $parent = $categoryRepository->findOneBy(['slug' => 'parent']);
      $child->setParent($parent);
      
  3. SEO Optimization:

    • Populate SEO fields (metaTitle, metaDescription, keywords) in the EasyAdmin form or via code:
      $post->setMetaTitle('Custom SEO Title');
      
  4. FAQ Integration:

    • Link FAQs to posts in EasyAdmin or via:
      $faq = new Faq();
      $faq->setQuestion('FAQ Question')->setAnswer('FAQ Answer');
      $post->addFaq($faq);
      

Integration Tips

  • Frontend Rendering: Use Twig to fetch and display posts:

    {% for post in posts %}
        <h2>{{ post.title }}</h2>
        <p>{{ post.content|truncate(200) }}</p>
        <a href="{{ path('blog.post', {'slug': post.slug}) }}">Read More</a>
    {% endfor %}
    
  • Pagination: Leverage the pagination.page_size config (default: 5) or override in templates:

    {{ knp_pagination_render(posts) }}
    
  • API Endpoints: Extend the blog.ajax.posts route for dynamic content (e.g., post sliders):

    fetch('/ajax/posts')
        .then(response => response.json())
        .then(posts => {
            // Render posts dynamically
        });
    
  • Custom Fields: Extend the Post entity (e.g., add featuredImage):

    #[ORM\Column(type: 'string', nullable: true)]
    private ?string $featuredImage = null;
    

    Update the EasyAdmin CRUD configuration to include the new field.


Gotchas and Tips

Pitfalls

  1. User Entity Requirement:

    • Forgetting to implement AuthorAwareInterface or configure user_entity in easy_blog.yaml will break post-author associations.
    • Fix: Verify the User entity implements getPosts() and addPost() methods.
  2. Slug Conflicts:

    • Duplicate slugs (e.g., /beitraege/hello-world) will cause 404 errors.
    • Fix: Use EasyAdmin’s built-in slug validation or override the slugify logic in your User entity.
  3. Template Overrides:

    • Overriding templates in the wrong directory (e.g., templates/EasyBlog/ instead of templates/bundles/EasyBlog/) will fail silently.
    • Fix: Ensure templates are placed in templates/bundles/EasyBlog/blog/.
  4. VichUploader Misconfiguration:

    • If vich_uploader is enabled but upload_dir is incorrect, images won’t save.
    • Fix: Set upload_dir to a writable directory (e.g., public/uploads/blog/).
  5. EasyAdmin Permissions:

    • Users without ROLE_ADMIN may not see the blog menu items.
    • Fix: Add permissions to your security configuration:
      security:
          access_control:
              - { path: ^/admin/blog, roles: ROLE_ADMIN }
      

Debugging Tips

  • Doctrine Events: Listen for post.persist or post.update to log or validate data:

    $eventManager->addEventListener(Post::class, function (LifecycleEventArgs $args) {
        $post = $args->getObject();
        if ($post->getSlug() === null) {
            throw new \RuntimeException('Slug cannot be null!');
        }
    });
    
  • Cache Issues: Clear the cache after configuration changes:

    php bin/console cache:clear
    php bin/console easyadmin:cache:clear
    
  • Route Debugging: Dump routes to verify blog.post exists:

    php bin/console debug:router | grep blog.post
    

Extension Points

  1. Custom Post Types: Extend the Post entity or create a trait for reusable logic:

    trait CustomPostFields {
        #[ORM\Column(type: 'boolean')]
        private bool $isFeatured = false;
    
        public function isFeatured(): bool { return $this->isFeatured; }
    }
    
  2. Event Subscribers: Hook into post lifecycle events (e.g., send notifications on publish):

    class PostSubscriber implements EventSubscriber {
        public static function getSubscribedEvents(): array {
            return [
                PostEvents::POST_PUBLISH => 'onPostPublish',
            ];
        }
    
        public function onPostPublish(PostEvent $event): void {
            // Send email, log activity, etc.
        }
    }
    
  3. Repository Extensions: Add custom query methods to PostRepository:

    public function findFeaturedPosts(int $limit = 3): array {
        return $this->createQueryBuilder('p')
            ->where('p.isFeatured = :featured')
            ->setParameter('featured', true)
            ->orderBy('p.createdAt', 'DESC')
            ->setMaxResults($limit)
            ->getQuery()
            ->getResult();
    }
    
  4. Twig Extensions: Create a custom Twig filter for post excerpts:

    class PostExtension extends \Twig\Extension\AbstractExtension {
        public function getFilters(): array {
            return [
                new \Twig\TwigFilter('post_excerpt', [$this, 'excerptFilter']),
            ];
        }
    
        public function excerptFilter(string $content, int $length = 100): string {
            return substr($content, 0, $length) . '...';
        }
    }
    

    Register it in services.yaml:

    services:
        App\Twig\PostExtension:
            tags: ['twig.extension']
    
  5. Form Customization: Override EasyAdmin’s post form in your config/easyadmin.yaml:

    easy_admin:
        entities:
            Post:
                form:
                    fields:
                        - { property: 'title', type: 'text' }
                        - { property: 'content', type: 'ckeditor' }
                        - { property: 'featuredImage', type: 'vich_image' }
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony