Laravel Filament Flexible Content Blocks 包可帮助您在 Filament 中轻松为任何模型创建内容,使用预定义或自定义块,以及 foreach 循环。
Laravel Filament Flexible Content Blocks 包可帮助您在 Filament 中轻松为任何模型创建内容,使用预定义或自定义块,以及 foreach 循环。
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:
:sparkles: New features:
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.
| 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 |
The image conversions in the configuration file have changed due to a refactor of spatie-medialibrary v11. Check the upgrade guide for details.
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.
You can install the package via composer:
composer require statikbe/laravel-filament-flexible-content-blocksYou will most likely need to edit the extensive configuration, so you can publish the config file with:
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:
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:
php artisan vendor:publish --tag="filament-flexible-content-blocks-migrations"
#first edit the migrations and then run:
php artisan migrateWhen 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:
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:
{
"scripts": {
"post-update-cmd": [
"@php artisan vendor:publish --tag=filament-flexible-content-blocks-assets --force"
]
}
}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 slugsspatie/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 ;-).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:
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.
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.
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:
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.
This adds an introduction text variable. Implement this interface with the trait HasIntroAttributeTrait or HasTranslatedIntroAttributeTrait.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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,或尚未同步最近议题。