百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-filament-flexible-content-blocks

> 后端框架
开源

Laravel Filament Flexible Content Blocks 包可帮助您在 Filament 中轻松为任何模型创建内容,使用预定义或自定义块,以及 foreach 循环。

179 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Laravel Filament Flexible Content Blocks 包可帮助您在 Filament 中轻松为任何模型创建内容,使用预定义或自定义块,以及 foreach 循环。

Laravel Filament Flexible Content Blocks

The Laravel Filament Flexible Content Blocks package helps you to easily create content in Filament for any model, with predefined blocks, and for each block an extendable Blade view component.

You can use this opinionated package to create a basic CMS, by setting up your own page model and implementing the predefined traits to select the functionality you need, then quickly setup a Filament resource by implementing the ready-made fields. Or you can add flexible content to a model for your specific business case, for instance to allow the flexible creation of a product description. Each project is different and to foster changing requirements, the focus is on the building blocks and not a default implementation for a CMS-like page.

The key goals of this package are:

  • provide a quick way to add content to a model through reusable fields and content blocks
  • quickly set up the frontend and allow different frontend stylings for each block
  • have fully-working, extendable Blade view components with basic Tailwind styling
  • allow the liberty to pick and choose which fields and blocks you need for your requirements
  • provide easy configuration to override the behaviour of the fields, blocks and image conversions
  • support SEO
  • support overview fields to display the content in a list with custom title, image and description
  • support content translations
  • provide a start set of content blocks for most general requirements

:sparkles: New features:

  • Improved styling of the blocks in Filament to improve UX when editing many blocks.
  • Replicate action to copy the model with content blocks and its images.
  • Content block previews! You can now show a preview of what the block looks like on the actual page, styled with the correct stylesheet. See the preview block configuration.
  • :art: Simple asset manager, see Filament Flexible Blocks Asset Manager

NOTE: :rocket: For a complete, out-of-the-box, content management solution, check out our new Filament Flexible Content Block Pages package with page management, a menu builder, tag management and many SEO features.

Versions & compatibility

Filament Version Package Version Development Branch
v3 statikbe/laravel-filament-flexible-content-blocks:^3.0 v3
v4 & v5 statikbe/laravel-filament-flexible-content-blocks:^4.0 main

Upgrades

Upgrade to v2

The image conversions in the configuration file have changed due to a refactor of spatie-medialibrary v11. Check the upgrade guide for details.

Upgrade to v1

If you need to upgrade to v1.0.0 it is IMPORTANT to read the upgrade guide thoroughly, because the data model of the content blocks has changed and needs to be upgraded via a command.

Installation

You can install the package via composer:

bash
composer require statikbe/laravel-filament-flexible-content-blocks

You will most likely need to edit the extensive configuration, so you can publish the config file with:

bash
php artisan vendor:publish --tag="filament-flexible-content-blocks-config"

Optionally, you can publish the views (e.g. if you want to tweak the content blocks) using:

bash
php artisan vendor:publish --tag="filament-flexible-content-blocks-views"

Since you can apply the flexible content blocks to any view, we do not provide required or default migrations. However, we provide two example migrations, one for a translatable page and one for a single-language page. You can use these migrations as an example to create your own migrations. (see ToDo's) You can publish and run the migrations with:

bash
php artisan vendor:publish --tag="filament-flexible-content-blocks-migrations"
#first edit the migrations and then run:
php artisan migrate

Optional installation steps

When you want to use the BackgroundVideo component, you have to make sure that the javascript files, which are used by the component, are available in your project. To do this, you have to publish the compiled javascript assets by using:

bash
php artisan vendor:publish --tag="filament-flexible-content-blocks-assets"

To automate the above, so that these assets will be re-published each time you perform a composer update, you can add the following publish command within the scripts.post-update-cmd array of your composer.json:

json
{
    "scripts": {
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=filament-flexible-content-blocks-assets --force"
        ]
    }
}

Dependencies

This is an opinionated package with batteries included. So we picked a set of dependencies to build upon. Here is a brief overview of the choices made:

  • filament/filament: obviously ;-)
  • spatie/laravel-medialibrary & filament/spatie-laravel-media-library-plugin: all image handling is done with spatie/medialibrary
  • spatie/laravel-sluggable: for slugs
  • spatie/laravel-translatable: for translations as this works together with the first party filament translatable package.
  • dereuromark/media-embed: to support video embeds of various media services.
  • openai-php/laravel: to generate content and add other smart features ;-).

Usage

If you are looking for a CMS-like page builder that makes use of this content blocks package, check out our Filament Flexible Content Block Pages. If you want to apply it to a different context, there is an example project of all the package features, which includes:

  • migrations
  • data models for default & translatable pages
  • Filament resources & pages
  • Http controllers
  • views
  • a data seeder to generate test pages

You can use this as a starting point to see how the package can be used for a CMS pages. Below we briefly discuss how to setup a migration, a model and a Filament resource in four steps. In the future, we want to add question-based commands to create these, see roadmap.

1. Setup migrations

You can start from the example migrations that can be published. Then prune and pick the fields that fit your requirements, note that some model traits need a combination of fields, e.g. the hero image needs both hero_image_copyright and hero_image_title. The clusters are commented in the migration or have a look in the model traits to get an idea.

2. Setup the model

If you do not have a model yet, create one with php artisan make:model, then you can add the interfaces and its default implementation via traits. Below is an overview of the provided interfaces and traits and their functionality:

HasPageAttributes:

This adds a title and publishing begin and end date variables, together with functions and scopes to help with finding published models. Implement this interface with the trait HasPageAttributesTrait or HasTranslatedPageAttributesTrait for translated content.

HasIntroAttribute:

This adds an introduction text variable. Implement this interface with the trait HasIntroAttributeTrait or HasTranslatedIntroAttributeTrait.

HasCode:

Adds a code variable to be able to select a specific content model in your source code by string instead of a varying id or slug. For instance, this is useful to look up a home page. Implement this with the trait HasCodeTrait.

HasHeroImageAttributes:

Adds a hero image as well as a title (e.g. for accessibility in alt tags) and copyright variable to the model. This can be implemented with HasHeroImageAttributesTrait and HasTranslatedHeroImageAttributesTrait.

HasHeroVideoUrlAttribute:

Adds a hero video URL that can be used to create a hero with a video playing in the background. This can be implemented with HasHeroVideoAttributeTrait and HasTranslatedHeroVideoUrlAttributeTrait.

HasContentBlocks:

Adds a JSON column to your model to store the data of the flexible content blocks. This is required if you want to use the flexible content blocks. Implement it with HasContentBlocksTrait or HasTranslatedContentBlocksTrait.

HasMediaAttributes:

This provides some helper functions for handling media. You do not need to add traits, since the trait will be included by other traits that handle images.

HasTranslatableMedia:

If you want to support translatable media (e.g. a different image for each locale), include this interface. The implementation is done by the trait HasTranslatedAttributesTrait.php. The traits that implement translatable images, will make use of this implementation to keep track of the media that needs translation.

HasOverviewAttributes:

Overview fields can be used to display the content models as brief snippets in lists, for instance a list of news articles. Implement this with HasOverviewAttributesTrait or HasTranslatedOverviewAttributesTrait.

HasSEOAttributes:

This adds a new title, description, image and keywords for SEO. It provides fallbacks to the regular title, intro and hero image if no SEO fields are completed. Implement the HasSEOAttributesTrait or the HasTranslatedSEOAttributesTrait for translatable content.

Linkable:

Add this interface if you want to use the model to link in call-to-actions to create dynamic URL's, or if you want to use the view action in the Filament table. The interface asks you to implement two functions one to get the url where the content can be publicly viewed and another to view the unpublished content. There is no default implementation trait, because this package is unaware of the used routes and controllers.

Slugs:

For slug support you can include the HasSlugAttributeTrait or the HasTranslatedSlugAttributeTrait for translatable slugs. If you use translatable slugs, please change [the page routing the Filam

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPcontent-managementfilamentfilamentphplaravel

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架