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

Cms Laravel Package

craftcms/cms

Craft CMS is a flexible, user-friendly PHP content management system for building custom websites and applications. It combines a clean authoring experience with powerful templating, structured content, and an extensible plugin ecosystem for developers.

Deep Wiki
Context7

Getting Started

First Steps

  1. Installation

    • Require via Composer:
      composer require craftcms/cms
      
    • Publish the package assets (if needed):
      php craft install
      
    • Run migrations:
      php craft migrate/up
      
  2. Initial Setup

    • Configure config/app.php (Craft’s core config file).
    • Define your first Field Type, Plugin, or Module in config/app.php under components or via CLI:
      php craft plugin/install my-plugin
      
  3. First Use Case: Creating a Custom Field

    • Extend craft\fields\BaseField to build a reusable field type.
    • Example:
      // plugins/MyPlugin/fields/MyField.php
      namespace myplugin\fields;
      
      use craft\fields\BaseField;
      
      class MyField extends BaseField {
          public $type = 'myField';
          public static function displayName(): string { return 'My Custom Field'; }
      }
      
    • Register it in config/app.php:
      'components' => [
          'fields' => [
              'myField' => \myplugin\fields\MyField::class,
          ],
      ],
      

Implementation Patterns

Core Workflows

  1. Content Modeling

    • Define Sections, Entry Types, and Fields via:
      • Control Panel UI (for quick prototyping).
      • Config files (for version control):
        // config/sections/mySection.php
        return [
            'type' => \craft\sections\Channel::class,
            'handle' => 'mySection',
            'name' => 'My Section',
            'entryTypes' => ['myEntryType'],
        ];
        
    • Use Element Queries to fetch content:
      $entries = craft()->elements->getContentByType('myEntryType');
      
  2. Plugin Development

    • Service Providers: Register services in Plugin.php:
      public function init()
      {
          parent::init();
          $this->setComponents([
              'myService' => \myplugin\services\MyService::class,
          ]);
      }
      
    • Controllers: Extend craft\web\Controller for API routes:
      public function actionMyAction()
      {
          return $this->asJson(['success' => true]);
      }
      
  3. Templates & Twig

    • Use Twig for dynamic rendering:
      {% set entries = craft.entries.section('mySection').all() %}
      {% for entry in entries %}
          {{ entry.title }}
      {% endfor %}
      
    • Template Hooks: Extend base templates via templates/_layouts/ or templates/_includes/.
  4. API & Webhooks

    • REST API: Enable in config/general.php:
      'enableApi' => true,
      
    • Webhooks: Listen to events (e.g., ELEMENT_SAVE):
      Event::on(
          Entry::class,
          Entry::EVENT_AFTER_SAVE,
          function (Event $event) {
              // Handle saved entry
          }
      );
      

Integration Tips

  • Laravel Integration: Use Craft’s Service Provider to bind Laravel services:
    public function boot()
    {
        $this->app->bind('myLaravelService', function () {
            return new \App\Services\MyService();
        });
    }
    
  • Asset Bundles: Use Web Asset Manager for JS/CSS:
    craft()->assets->registerAssetBundle('MyPlugin', \myplugin\web\assets\MyAsset::class);
    
  • Queue Jobs: Leverage Laravel’s queue system for background tasks:
    dispatch(new \myplugin\jobs\ProcessDataJob($data));
    

Gotchas and Tips

Common Pitfalls

  1. Caching Quirks

    • Clear caches after config changes:
      php craft clear-caches/all
      
    • Use craft()->cache->clear() in plugins for dynamic updates.
  2. Element Query Pitfalls

    • N+1 Queries: Use .preferRelatedElements() or .with():
      $entries->with(['relatedField']);
      
    • Performance: Limit results with .limit() or .offset().
  3. Plugin Autoloading

    • Ensure composer.json has correct autoload:
      {
          "autoload": {
              "psr-4": {
                  "myplugin\\": "plugins/my-plugin/src"
              }
          }
      }
      
    • Run composer dump-autoload after changes.
  4. Migration Conflicts

    • Always back up before running migrations.
    • Use --dry-run to preview changes:
      php craft migrate/diff --dry-run
      

Debugging Tips

  • Error Logging: Check storage/logs/ for Craft-specific logs.
  • Xdebug: Configure for Craft’s index.php entry point.
  • Twig Debug: Enable in config/general.php:
    'devMode' => true,
    'templateDebugMode' => true,
    

Extension Points

  1. Event System
    • Listen to Craft Events (e.g., ELEMENT_CHANGE, USER_LOGIN):
      Event::on(
          User::class,
          User::EVENT_AFTER_LOGIN,
          function (Event $event) {
              // Custom logic
          }
      );
      
  2. CP Widgets
    • Extend the Control Panel with custom widgets:
      craft()->cp->addDashboardWidget([
          'class' => \myplugin\widgets\MyWidget::class,
      ]);
      
  3. Field Layouts
    • Dynamically modify field layouts via FIELD_LAYOUT_REGISTER event:
      Event::on(
          FieldLayout::class,
          FieldLayout::EVENT_REGISTER_LAYOUT_TYPES,
          function (Event $event) {
              $event->sender->layoutTypes[] = 'myCustomLayout';
          }
      );
      

Pro Tips

  • Use craft()->config->get() for dynamic config values.
  • Leverage craft()->elements->getCriteria() for reusable queries.
  • Test Plugins with php craft test (if using Pest/PHPUnit).
  • Localization: Use Craft’s t() function for translations:
    craft()->i18n->getTranslation('my-plugin', 'my-key');
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport