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

bloghoven/blog-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bloghoven/blog-bundle
    

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

    Bloghoven\BlogBundle\BloghovenBlogBundle::class => ['all' => true],
    
  2. Publish Assets & Config

    php artisan vendor:publish --provider="Bloghoven\BlogBundle\BloghovenBlogBundle" --tag="config"
    php artisan vendor:publish --provider="Bloghoven\BlogBundle\BloghovenBlogBundle" --tag="public"
    

    This generates:

    • config/bloghoven.php (default config)
    • Assets in public/vendor/bloghoven/
  3. First Use Case: Displaying a Blog Post Inject the BlogPostRepository into a controller:

    use Bloghoven\BlogBundle\Repository\BlogPostRepository;
    
    public function showPost(BlogPostRepository $posts)
    {
        $post = $posts->find(1); // Fetch by ID
        return view('blog.post', compact('post'));
    }
    

    Create a Blade template (resources/views/blog/post.blade.php):

    <h1>{{ $post->title }}</h1>
    <div>{!! $post->content !!}</div> <!-- Supports HTML -->
    

Implementation Patterns

Core Workflows

  1. CRUD Operations Use the repository pattern for all blog operations:

    // Create
    $post = $posts->create([
        'title' => 'Laravel Tips',
        'slug' => 'laravel-tips',
        'content' => '<p>Tip 1: Use...</p>',
        'author_id' => auth()->id(),
    ]);
    
    // Update
    $posts->update($post->id, ['title' => 'Updated Title']);
    
    // Delete
    $posts->delete($post->id);
    
  2. Querying Posts Filter posts via the repository:

    // By category
    $posts = $posts->findBy(['category' => 'laravel']);
    
    // Published only
    $posts = $posts->findBy(['published_at' => null]); // Non-null = published
    
    // Paginated list
    $posts = $posts->findAll(['limit' => 10, 'offset' => 0]);
    
  3. Taxonomy Management Use BlogCategoryRepository and BlogTagRepository:

    $categories = $categories->findAll();
    $tags = $tags->findBy(['post_id' => $post->id]);
    
  4. Asset Handling Upload images via the BlogPostImageUploader service:

    $uploader = app('bloghoven.blog_post_image_uploader');
    $path = $uploader->upload($request->file('image'));
    

Integration Tips

  • Form Requests: Extend Bloghoven\BlogBundle\Form\Type\BlogPostType for custom validation.
  • Events: Listen to blog.post.created or blog.post.updated for post-processing (e.g., notifications).
  • APIs: Use the BlogPostResource (if provided) for API responses:
    return new BlogPostResource($post);
    

Gotchas and Tips

Pitfalls

  1. Slug Conflicts

    • The bundle auto-generates slugs from titles. Override with slug field in create()/update() to avoid collisions.
    • Fix: Use a unique slug generator or validate manually:
      if ($posts->exists(['slug' => $slug])) {
          $slug = Str::slug($title . ' ' . time());
      }
      
  2. Content Sanitization

    • The content field accepts raw HTML. Sanitize user input to prevent XSS:
      use Symfony\Component\DomCrawler\Crawler;
      $cleanContent = (new Crawler($post->content))->html();
      
  3. Database Migrations

    • The bundle includes migrations, but custom fields (e.g., meta_title) require manual migration:
      php artisan make:migration add_meta_to_posts --table=blog_posts
      
  4. Caching Quirks

    • Repository methods may not cache results by default. Enable caching in config:
      'cache' => [
          'enabled' => true,
          'ttl' => 3600, // 1 hour
      ],
      

Debugging

  • SQL Logs: Enable Laravel’s query logging to inspect raw SQL:
    \DB::enableQueryLog();
    $posts->find(1);
    dd(\DB::getQueryLog());
    
  • Event Debugging: Dump events in EventSubscriber:
    public function onPostCreated(PostCreatedEvent $event)
    {
        \Log::debug('Post created:', ['post' => $event->getPost()]);
    }
    

Extension Points

  1. Custom Fields Extend the BlogPost entity or use a trait:

    namespace App\Models;
    use Bloghoven\BlogBundle\Entity\BlogPost as BasePost;
    
    class BlogPost extends BasePost
    {
        protected $customField = 'value';
    }
    
  2. Override Templates Copy vendor templates to your project (e.g., resources/views/vendor/bloghoven/) to customize:

    • post/show.html.twig (Symfony) or post.blade.php (Laravel).
  3. Add Validation Extend the form type:

    namespace App\Form\Type;
    use Bloghoven\BlogBundle\Form\Type\BlogPostType as BaseType;
    
    class BlogPostType extends BaseType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('custom_field', TextType::class);
        }
    }
    
  4. API Extensions Create a custom resource:

    namespace App\Http\Resources;
    use Bloghoven\BlogBundle\Http\Resources\BlogPostResource as BaseResource;
    
    class CustomPostResource extends BaseResource
    {
        public function toArray($request)
        {
            $array = parent::toArray($request);
            $array['custom_data'] = $this->customField;
            return $array;
        }
    }
    
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