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

brt/blog-bundle

Laravel blog bundle providing posts, categories, tags, and basic blog routes/views. Quick setup for adding a simple blog section to an existing app, with migrations and optional admin tooling depending on configuration.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps for Laravel Adoption

  1. Abandon Direct Use: This bundle is not Laravel-compatible. Instead, use these alternatives:

    • For a quick blog: Install Laravel Nova (if on Laravel 8+) or October CMS.
    • For custom development: Scaffold a blog with:
      composer require laravel/nova laravel/breeze --dev
      php artisan nova:install
      php artisan breeze:install blog
      
  2. First Use Case (Laravel Alternative): Create a post model and migration:

    php artisan make:model Post -m
    

    Define migration (database/migrations/..._create_posts_table.php):

    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('content');
        $table->string('slug')->unique();
        $table->foreignId('user_id')->constrained();
        $table->timestamps();
    });
    

    Run migration:

    php artisan migrate
    

    Create a controller:

    php artisan make:controller PostController --resource
    

    Add routes (routes/web.php):

    Route::resource('posts', PostController::class);
    
  3. Where to Look First:


Implementation Patterns

Laravel-Centric Workflows

  1. Model-View-Controller (MVC) Pattern:

    • Model: Define Post with relationships (e.g., belongsTo(User)).
      // app/Models/Post.php
      namespace App\Models;
      use Illuminate\Database\Eloquent\Model;
      class Post extends Model {
          public function user() { return $this->belongsTo(User::class); }
      }
      
    • Controller: Use resource controllers for CRUD.
      // app/Http/Controllers/PostController.php
      public function index() {
          return view('posts.index', ['posts' => Post::latest()->paginate(10)]);
      }
      
    • View: Blade templates for rendering.
      <!-- resources/views/posts/index.blade.php -->
      @foreach($posts as $post)
          <article>
              <h2>{{ $post->title }}</h2>
              <p>{{ Str::limit($post->content, 200) }}</p>
          </article>
      @endforeach
      
  2. File Uploads (Replacing VichUploader):

    • Install Spatie Media Library:
      composer require spatie/laravel-medialibrary
      php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider"
      
    • Add to Post model:
      use Spatie\MediaLibrary\HasMedia;
      use Spatie\MediaLibrary\InteractsWithMedia;
      class Post extends Model implements HasMedia {
          use InteractsWithMedia;
      }
      
    • Upload logic in controller:
      public function store(Request $request) {
          $post = Post::create($request->validate([
              'title' => 'required',
              'content' => 'required',
              'image' => 'nullable|image'
          ]));
          if ($request->hasFile('image')) {
              $post->addMediaFromRequest('image')->toMediaCollection('images');
          }
          return redirect()->route('posts.show', $post);
      }
      
  3. Pagination (Replacing KnpPaginator):

    • Laravel’s built-in pagination:
      $posts = Post::latest()->paginate(10); // Returns a LengthAwarePaginator
      
    • Customize views:
      {{ $posts->links() }} <!-- Default pagination links -->
      
    • Tailor pagination:
      $posts = Post::latest()->paginate(10, ['*'], 'custom');
      
  4. CLI Commands (Replacing Bundle Commands):

    • Create a custom command:
      php artisan make:command CreatePost
      
    • Define logic:
      // app/Console/Commands/CreatePost.php
      public function handle() {
          $post = Post::create([
              'title' => $this->ask('Title'),
              'content' => $this->ask('Content'),
              'slug' => Str::slug($this->ask('Slug')),
              'user_id' => auth()->id()
          ]);
          $this->info("Post created: {$post->slug}");
      }
      
    • Register in app/Console/Kernel.php:
      protected $commands = [
          \App\Console\Commands\CreatePost::class,
      ];
      
    • Run:
      php artisan create:post
      
  5. User Integration:

    • Use Laravel’s built-in User model or extend it:
      // app/Models/User.php
      public function posts() { return $this->hasMany(Post::class); }
      
    • Authenticate via Laravel’s auth() helper or middleware:
      Route::middleware(['auth'])->group(function () {
          Route::resource('posts', PostController::class);
      });
      
  6. Service Providers (Replacing Symfony Services):

    • Register custom services in AppServiceProvider:
      public function register() {
          $this->app->singleton('postRepository', function () {
              return new \App\Repositories\PostRepository;
          });
      }
      
    • Bind interfaces to implementations:
      $this->app->bind(
          \App\Contracts\PostRepository::class,
          \App\Repositories\EloquentPostRepository::class
      );
      
  7. Events (Replacing Symfony Events):

    • Define events:
      php artisan make:event PostCreated
      
    • Listen to events:
      // app/Providers/EventServiceProvider.php
      protected $listen = [
          \App\Events\PostCreated::class => [
              \App\Listeners\NotifyPostAuthor::class,
          ],
      ];
      
    • Dispatch events:
      event(new PostCreated($post));
      

Gotchas and Tips

Pitfalls

  1. Symfony-Specific Assumptions:

    • Doctrine Annotations: The bundle uses @ORM\*, which Laravel’s Eloquent does not support. Replace with Eloquent attributes (PHP 8+) or fluent methods:
      // Symfony (Doctrine)
      /** @ORM\ManyToOne(targetEntity="User") */
      private $user;
      
      // Laravel (Eloquent)
      public function user() { return $this->belongsTo(User::class); }
      
    • Twig Syntax: Avoid {% extends %} or {{ asset() }} in templates. Use Blade:
      @extends('layouts.app')
      @section('content')
          <img src="{{ asset('storage/' . $post->image) }}">
      @endsection
      
  2. Database Schema Mismatches:

    • The bundle assumes User extends Symfony’s User class. In Laravel, use:
      // app/Models/User.php
      use Illuminate\Foundation\Auth\User as Authenticatable;
      class User extends Authenticatable { ... }
      
    • Foreign keys may need adjustment (e.g., user_id vs. author_id).
  3. Routing Conflicts:

    • Symfony routes use YAML/annotations. Laravel uses:
      Route::get('/posts/{post:slug}', [PostController::class, 'show']);
      
    • Avoid route caching conflicts by using explicit route names:
      Route::name('posts.show')->get('/posts/{post}', ...);
      
  4. Dependency Injection:

    • Symfony uses ContainerAware or autowiring via annotations. Laravel uses:
      public function __construct(private PostRepository $posts) {}
      
    • Avoid new instantiations; use dependency injection.
  5. File Upload Paths:

    • VichUploader uses vich_uploader.destination. In Laravel, configure spatie/laravel-medialibrary in .env:
      MEDIA_LIBRARY_DISK=public
      
    • Ensure public/storage is symlinked:
      php artisan storage:link
      
  6. Pagination Quirks:

    • KnpPaginator uses Knp\Component\Pager\PaginatorInterface. Laravel
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