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

Lara Cms Laravel Package

appdezign/lara-cms

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require appdezign/lara-cms
    php artisan vendor:publish --provider="Appdezign\LaraCms\LaraCmsServiceProvider"
    php artisan migrate
    
    • Publish config, migrations, and assets to config/lara-cms.php, database/migrations/, and public/vendor/lara-cms/.
  2. First Use Case:

    • Create a content type (e.g., Article) via the admin panel or manually:
      use Appdezign\LaraCms\Models\ContentType;
      ContentType::create(['name' => 'article', 'slug' => 'articles']);
      
    • Add fields to the content type:
      $contentType->fields()->create(['name' => 'title', 'type' => 'text']);
      $contentType->fields()->create(['name' => 'body', 'type' => 'textarea']);
      
    • Create content for the type:
      use Appdezign\LaraCms\Models\Content;
      Content::create([
          'content_type_id' => $contentType->id,
          'data' => json_encode(['title' => 'Hello World', 'body' => 'Lara CMS is awesome!']),
      ]);
      
  3. Display Content:

    • Use Blade to render content:
      @foreach(\Appdezign\LaraCms\Models\Content::where('content_type_id', $articleTypeId)->get() as $content)
          <h1>{{ $content->data->title }}</h1>
          <p>{{ $content->data->body }}</p>
      @endforeach
      
    • Or fetch via API:
      route('api.cms.content.index', ['type' => 'articles']);
      
  4. Admin Panel:

    • Access /admin/cms (default route) to manage content types, fields, and entries.
    • Customize the admin panel by extending the Appdezign\LaraCms\Http\Controllers\AdminController.

Where to Look First

  • Documentation: Start with LaraCMS Docs for setup, configuration, and API references.
  • Config File: config/lara-cms.php for route prefixes, middleware, and default settings.
  • Migrations: database/migrations/ for schema changes (e.g., content_types, contents, fields).
  • Models: appdezign/lara-cms/src/Models/ for Eloquent relationships and business logic.
  • Routes: routes/web.php and routes/api.php for CMS-specific endpoints (e.g., /api/cms/content).

Implementation Patterns

Usage Patterns

1. Content-Type Driven Development

  • Pattern: Define content types as Laravel models with dynamic fields.
  • Example:
    // Define a 'Product' content type
    $productType = ContentType::create(['name' => 'Product', 'slug' => 'products']);
    $productType->fields()->createMany([
        ['name' => 'name', 'type' => 'text'],
        ['name' => 'price', 'type' => 'number'],
        ['name' => 'description', 'type' => 'textarea'],
        ['name' => 'image', 'type' => 'media'], // Assuming media field type exists
    ]);
    
  • Use Case: E-commerce products, blog posts, or custom landing pages.

2. API-First Content Delivery

  • Pattern: Expose content via Laravel’s API resources or custom endpoints.
  • Example:
    // routes/api.php
    Route::get('/products', [ContentController::class, 'index'])->name('api.cms.products.index');
    
    // app/Http/Controllers/ContentController.php
    public function index()
    {
        return Content::with('contentType.fields')
            ->where('content_type_id', $productTypeId)
            ->get();
    }
    
  • Use Case: Headless CMS for React/Vue frontends or mobile apps.

3. Field-Level Customization

  • Pattern: Extend or override field types (e.g., add validation, custom UI).
  • Example:
    // Extend the 'text' field type
    namespace App\Extensions\LaraCms\Fields;
    
    use Appdezign\LaraCms\Fields\TextField;
    
    class CustomTextField extends TextField
    {
        public function getRules()
        {
            return ['required', 'max:255', 'unique:contents,data->title'];
        }
    }
    
    Register the extension in config/lara-cms.php:
    'field_extensions' => [
        'text' => \App\Extensions\LaraCms\Fields\CustomTextField::class,
    ],
    

4. Workflow Automation

  • Pattern: Use Laravel events and observers to automate content workflows.
  • Example:
    // app/Observers/ContentObserver.php
    use Appdezign\LaraCms\Models\Content;
    use Illuminate\Support\Facades\Log;
    
    Content::observe(function ($content) {
        if ($content->wasRecentlyCreated) {
            Log::info("New content created: {$content->id}");
            // Trigger email, Slack notification, etc.
        }
    });
    
    Register the observer in AppServiceProvider:
    Content::observe(\App\Observers\ContentObserver::class);
    

5. Multi-Tenancy (If Supported)

  • Pattern: Scope content to tenants using Laravel’s tenant() helper or middleware.
  • Example:
    // Middleware to scope content by tenant
    public function handle($request, Closure $next)
    {
        $tenant = auth()->user()->tenant;
        Content::addGlobalScope('tenant', function ($query) use ($tenant) {
            $query->where('tenant_id', $tenant->id);
        });
        return $next($request);
    }
    

Workflows

1. Content Creation Workflow

  1. Define content type and fields (admin panel or code).
  2. Create content entries via:
    • Admin panel (/admin/cms/content/create).
    • API (POST /api/cms/content).
    • Code:
      Content::create([
          'content_type_id' => $typeId,
          'data' => json_encode($data),
          'user_id' => auth()->id(),
      ]);
      
  3. Publish content (if using workflows):
    $content->update(['status' => 'published']);
    

2. Content Update Workflow

  1. Fetch content:
    $content = Content::find($id);
    
  2. Update data:
    $content->update([
        'data' => json_encode(array_merge($content->data, ['title' => 'Updated Title'])),
    ]);
    
  3. Trigger events (e.g., cache invalidation, notifications).

3. Content Deletion Workflow

  • Soft delete (default):
    $content->delete(); // Sets 'deleted_at' column
    
  • Permanent delete (if needed):
    $content->forceDelete();
    

4. Media Handling Workflow

  • Upload media via the admin panel or API.
  • Attach media to content:
    $content->media()->attach($mediaId);
    
  • Display media in Blade:
    @foreach($content->media as $media)
        <img src="{{ $media->url }}" alt="{{ $media->name }}">
    @endforeach
    

Integration Tips

1. Laravel Ecosystem Integration

  • Eloquent: Treat Content, ContentType, and Field as Eloquent models.
  • Query Scopes: Add custom scopes to filter content:
    Content::addGlobalScope('published', function ($query) {
        $query->where('status', 'published');
    });
    
  • Policy: Restrict access to content:
    use Appdezign\LaraCms\Models\Content;
    use Illuminate\Auth\Access\HandlesAuthorization;
    
    class ContentPolicy
    {
        use HandlesAuthorization;
    
        public function viewAny($user)
        {
            return $user->can('view-cms-content');
        }
    }
    

2. Frontend Integration

  • Blade: Use @include for reusable CMS templates:
    @include('cms::partials.content', ['content' => $article])
    
  • Livewire: Bind CMS content to Livewire components:
    public $content;
    public function mount($id)
    {
        $this->content = Content::findOrFail($id);
    }
    
  • Inertia.js: Pass CMS data to Vue/React:
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.
calliostro/spotify-bundle
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle