phpsa / filament-headless-cms
filament 的无头 CMS
v1.1.0
2024-08-28 01:50 UTC
Requires
- php: ^8.1
- filament/filament: ^3.0
- filament/spatie-laravel-tags-plugin: ^3.2
- illuminate/contracts: ^10.0|^11.0
- motivo/filament-title-with-slug: ^1.0
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- larastan/larastan: ^2.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.3
- pestphp/pest-plugin-livewire: ^2.1
README
Filament Headless CMS
filament 无头 CMS 的起点 - 下文介绍了如何使用 API / 非 API
安装
您可以通过 composer 在您使用的面板中安装此包
composer require phpsa/filament-headless-cms php artisan filament-headless-cms::install
使用
public function panel(Panel $panel): Panel { return $panel ->default() ->id('admin') ->path('/admin') ... ->plugin(FilamentHeadlessCms::make())
在 Filament 中
模板
运行安装命令后,您将在 Filament 管理员中找到新的内容组和服务内容资源。
模板
此包包含基本的页面和博客类型模板。通过创建和选择您自己的模板,您能够完全自定义您的页面。
要创建自己的模板,请扩展 Phpsa\FilamentHeadlessCms\Contracts\PageTemplate
抽象类
<?php namespace App\Filament\PageTemplates; use Filament\Forms\Components\Section; use Filament\Forms\Components\Component; use Phpsa\FilamentHeadlessCms\Contracts\PageTemplate; use Phpsa\FilamentHeadlessCms\Filament\Fields\Editor; class CustomPageTemplate extends PageTemplate { public static function title(): string { return 'Custom Page'; } /** * @return array<int|string, Component> */ public static function schema(): array { return [ Section::make() ->schema([ Editor::make('content') ->label('Content'), ]) ]; } }
并在面板提供者中注册此内容:- 您可以选择清除示例模板或不使用 flush 参数保持它们。
FilamentHeadlessCms::make() ->setTemplates([ GrapeTemplate::class ], flush: false),
现在它将出现在内容区域下,并允许您创建/编辑/删除。
模板功能
能够控制表单本身是很好的,但假设您想在默认区域中添加某些内容:我们为您提供了支持。
以下是一些可以覆盖的项目
//change default pagination public static bool|array|Closure $paginate = true; //should the items be sortable? public static bool $sortable = false; protected static int $sortOrder = 0; // set the order in nav protected static bool $hasSeo = true; //no SEO, switch to false, why though? protected static bool $publishDates = true; // if you do not need to publish on a date and it should just be... :-) abstract public static function title(): string; //The value in here should be unique, it is the identifier for your template abstract public static function schema(): array; // the actual form main body area, you can do whatever here, sections, tabs, wizards, builders etc. public static function sidebarSchema(): array; //want to add another sidebar above the SEO? //add area before and after the title area public static function beforePrimaryColumnSchema(): array; public static function afterPrimaryColumnSchema(): array; // add area before and after the fields in the main sidebar public static function beforeSecondaryColumnSchema(): array; public static function afterSecondaryColumnSchema(): array; // need to manipulate the data for your api response? public static function toApiResponse(array $data): array { if (filled($data['featured_image'])) { $data['featured_image'] = Storage::disk(config('filament.default_filesystem_disk'))->url($data['featured_image']); } return $data; } //Update this if using laravel scout to setup your searchable information public function toSearchableArray(FilamentPage $record): array { return $this->apiTransform($record); }
插件定制
您可以使用以下方法进行定制
FilamentHeadlessCms::make() ->setResource(ResourceFile::class) // in case you want to customize it, you can extend the PageResource::class ->setModel(Model::class) // woudl recomend extending FhcmsContent - must implement FilamentPage ->setNavigation([ 'group' => 'Content', 'icon' => 'heroicon-o-document', 'sort' => null, 'parent' => null, 'icon_active' => 'heroicon-s-document', ]); ->setSiteUrl('https://xxxx') //--> defaults to config('app.frontend_url') ?? config('app.url') ->setTemplates(array $templates, bool $flush = false) // add or completely replace templates ->setUploadFormField(FileUpload::class) // if using default templates or built in upload class -- make sure to use this file uploader ->setEditorFormField(Editor::class) // which rich / markdown form field editor to use - if using default templates ->setApiMiddleware(['api']) // defaults to ['api'] ->setApiPrefix('api') // defaults to api
API 路由
api/fhcms/types
- 列出活动模板类型api/fhcms/types?with_counts
- 列出活动模板类型和已发布项的数量。fhcms/content-pages/{type}
- 类型 - 是 slug,将返回分页列表fhcms/content-pages/{type}/{slug}
- slug 是内容项的 slug。 - 以 JSON 格式返回项。
性能
我们将持续寻找改进性能的方法,从 V1.1.0 开始 - 我们将缓存内容页面的输出,每次 24 小时或直到记录更新。
计划中的功能/建议
- 这是一个新的项目,有增长和改进的空间,请随时提出改进建议或打开拉取请求。
当前计划
与 Scout 的搜索集成- 改进模板之间的内部引用。
- 改进测试
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
鸣谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。