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

Pando Content Bundle Laravel Package

blackboxcode/pando-content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your Laravel project via Composer:

    composer require blackboxcode/pando-content-bundle
    

    Register the bundle in config/app.php under providers:

    BlackBoxCode\PandoContentBundle\PandoContentBundle::class,
    
  2. Publish Configuration Publish the default config file:

    php artisan vendor:publish --provider="BlackBoxCode\PandoContentBundle\PandoContentBundle" --tag="config"
    

    Locate the config at config/pando_content.php.

  3. First Use Case: Basic Content Management Define a content type in a migration (e.g., pages):

    use BlackBoxCode\PandoContentBundle\Migrations\CreateContentTypeTable;
    Schema::create('content_types', function (Blueprint $table) {
        CreateContentTypeTable::create($table, 'pages');
    });
    

    Create a model extending PandoContentModel:

    use BlackBoxCode\PandoContentBundle\Models\PandoContentModel;
    class Page extends PandoContentModel { protected $contentType = 'pages'; }
    

    Insert content via Tinker or a controller:

    $page = new Page();
    $page->title = 'Home';
    $page->content = '<h1>Welcome</h1>';
    $page->save();
    

Implementation Patterns

Workflows

  1. Content Type Definition

    • Use migrations to define content types (e.g., articles, products).
    • Leverage CreateContentTypeTable for reusable schema logic.
    • Example:
      Schema::create('articles', function (Blueprint $table) {
          CreateContentTypeTable::create($table, 'articles');
          $table->string('slug')->unique();
          $table->text('excerpt');
      });
      
  2. Model Integration

    • Extend PandoContentModel for each content type.
    • Override getContentType() if needed:
      class Article extends PandoContentModel {
          protected $contentType = 'articles';
          public function getContentType() { return $this->contentType; }
      }
      
  3. Content Retrieval

    • Use Eloquent queries with the model:
      $articles = Article::where('published', true)->orderBy('created_at', 'desc')->get();
      
    • Fetch by content type via the bundle’s repository:
      $content = app(\BlackBoxCode\PandoContentBundle\Repositories\ContentRepository::class)
          ->findByType('pages', 1);
      
  4. Frontend Integration

    • Serve content via API routes:
      Route::get('/content/{type}/{id}', function ($type, $id) {
          return app(\BlackBoxCode\PandoContentBundle\Repositories\ContentRepository::class)
              ->findByType($type, $id);
      });
      
    • Use Blade templates to render dynamic content:
      @foreach($pages as $page)
          <h2>{{ $page->title }}</h2>
          {!! $page->content !!}
      @endforeach
      
  5. Content Versioning

    • Enable versioning in config/pando_content.php:
      'versioning' => [
          'enabled' => true,
          'table' => 'content_versions',
      ],
      
    • Access versions via relationships:
      $versions = $page->versions()->orderBy('created_at', 'desc')->get();
      

Gotchas and Tips

Pitfalls

  1. Content Type Naming

    • Ensure content type names (e.g., 'pages') match the table names exactly.
    • Mismatches cause ContentNotFoundException.
  2. Model Binding

    • If using route model binding, ensure the id column exists in the content table.
    • Override getRouteKeyName() if needed:
      public function getRouteKeyName() { return 'slug'; }
      
  3. JSON Fields

    • Avoid storing large JSON blobs in content fields. Use dedicated columns for structured data.
  4. Caching

    • Clear cache after content updates:
      Cache::forget("pando_content_{$contentType}_{$id}");
      

Debugging

  1. Query Logs Enable Laravel’s query logging to debug content retrieval:

    DB::enableQueryLog();
    $content = Article::find(1);
    dd(DB::getQueryLog());
    
  2. Content Type Existence Verify content types exist in the content_types table before querying.

  3. Versioning Conflicts If versioning is enabled, ensure the content_versions table exists and has the correct schema.

Extension Points

  1. Custom Fields Extend the PandoContentModel to add custom accessors/mutators:

    public function getFormattedContentAttribute() {
        return nl2br(e($this->content));
    }
    
  2. Events Listen for content events (e.g., ContentSaved):

    Event::listen(\BlackBoxCode\PandoContentBundle\Events\ContentSaved::class, function ($event) {
        // Log or notify on content changes
    });
    
  3. API Resources Create custom API resources for content:

    class PageResource extends JsonResource {
        public function toArray($request) {
            return [
                'title' => $this->title,
                'content' => $this->content,
                'slug' => $this->slug,
            ];
        }
    }
    
  4. Middleware Protect content routes with middleware:

    Route::get('/admin/content', function () {
        // ...
    })->middleware('can:manage-content');
    

Configuration Quirks

  • Default Values: Set default values in config/pando_content.php for fields like published_at.
  • Soft Deletes: Enable soft deletes globally or per-model:
    use SoftDeletes;
    class Page extends PandoContentModel {
        use SoftDeletes;
        protected $dates = ['deleted_at'];
    }
    
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.
craftcms/url-validator
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