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
Bauhausblock

Bauhausblock Laravel Package

krafthaus/bauhausblock

Laravel package for building “Bauhaus” content blocks/components for your app or CMS. Provides a structured way to define, render, and manage reusable blocks, helping you compose pages from modular content with minimal setup.

View on GitHub
Deep Wiki
Context7

Simple block handling for laravel

Frequently asked questions about Bauhausblock
What Laravel versions does krafthaus/bauhausblock support?
The package requires Laravel 8+ and PHP 8.0+. It’s designed for modern Laravel applications and leverages Eloquent, so ensure your project meets these baseline requirements before installation. Check your `composer.json` for compatibility if using Lumen or older Laravel versions.
How do I define a custom content block type?
Extend the `BlockServiceProvider` to register your block types. Use the `registerBlockTypes` method to define classes for each block (e.g., HeroBlock, TestimonialBlock). Each class should implement logic for rendering or processing block data. Refer to the package’s `BlockType` interface for required methods.
Can I use this package for a headless CMS or SPA?
Yes, but you’ll need to create custom API endpoints for block data. Use Laravel’s `Route::resource` or `apiResource` to expose blocks via JSON. Pair this with frontend frameworks like Vue or React to fetch and render blocks dynamically. No built-in API routes are provided, so manual setup is required.
How do I handle block ordering in the database?
The package expects a `sort_order` column in your blocks table to manage ordering. You can manually set this value when creating blocks or use Laravel’s query builder to reorder them. For drag-and-drop UIs, consider adding JavaScript to update `sort_order` via AJAX calls to your backend.
Does this package support nested blocks (blocks within blocks)?
No, the package does not natively support nested blocks. However, you can simulate nesting by storing block IDs in a `parent_id` column and querying recursively. For complex nested structures, consider extending the package or using a dedicated solution like Spatie’s Media Library for hierarchical content.
How do I render blocks in Blade templates?
Use Blade directives like `@foreach($blocks as $block)` to loop through blocks. Pass the block’s `type` and `data` to a corresponding view (e.g., `@include('blocks.'.$block->type, ['data' => $block->data])`). Ensure your block views are stored in a `resources/views/blocks` directory for organization.
What database schema is required for blocks?
You’ll need a `blocks` table with at least these columns: `id`, `page_id` (foreign key), `type` (string), `data` (JSON), `sort_order` (integer), and timestamps. The package doesn’t include migrations, so create them manually. Example: `Schema::create('blocks', function (Blueprint $table) { $table->id(); $table->foreignId('page_id')->constrained()->cascadeOnDelete(); $table->string('type'); $table->json('data'); $table->integer('sort_order'); $table->timestamps(); });`
Is there built-in caching for block rendering?
No, the package doesn’t include caching logic. Implement caching manually using Laravel’s cache system (e.g., `Cache::remember`) or Redis. Cache block collections or individual block renders based on your performance needs. Avoid caching dynamic blocks that change frequently without invalidation.
How do I validate block data before saving?
Use Laravel’s validation rules in your block creation logic. For example, validate the `data` JSON field with `['data' => 'required|json']` in a Form Request or manually in your controller. Extend the `Block` model or use accessors/mutators to enforce custom validation rules before saving to the database.
What alternatives exist for Laravel content blocks?
Consider Spatie’s `laravel-medialibrary` for media-rich blocks, October CMS for a full-fledged CMS, or `spatie/laravel-activitylog` for tracking block changes. For simpler needs, Laravel’s native Eloquent relationships or a custom solution with JSON columns may suffice. Evaluate based on your need for nesting, WYSIWYG, or real-time updates.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope