beier / filament-pages
针对filament的高度定制页面
Requires
- php: ^8.1
- filament/filament: ^2.0
- illuminate/contracts: ^9.0 || ^10.0
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- laravel/pint: ^1.2
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- pestphp/pest-plugin-livewire: ^1.0
- pestphp/pest-plugin-parallel: ^0.3
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-08-29 13:30:51 UTC
README
beier/filament-pages
创建页面资源和前端路由的起点,这是我们对Page CMS功能进行打包的结果。
此包不注册任何路由,因为页面路由始终取决于您的项目。这是为了为您提供创建动态页面模块的快速入门。
演示
截图
安装
您可以通过composer安装此包
composer require beier/filament-pages
您可以使用以下命令运行安装命令
php artisan filament-pages:install
这是发布配置文件的内容
<?php use Beier\FilamentPages\Filament\FilamentPageTemplates\DefaultTemplate; use Beier\FilamentPages\Filament\Resources\FilamentPageResource; use Beier\FilamentPages\Models\FilamentPage; use Beier\FilamentPages\Renderer\SimplePageRenderer; return [ 'filament' => [ /* |-------------------------------------------------------------------------- | Filament: Custom Filament Resource |-------------------------------------------------------------------------- | | Use your own extension of the FilamentPageResource | below to fully customize every aspect of it. | */ 'resource' => FilamentPageResource::class, /* |-------------------------------------------------------------------------- | Filament: Custom Filament Model |-------------------------------------------------------------------------- | | Use your own extension of the FilamentPage Model | below to fully customize every aspect of it. | */ 'model' => FilamentPage::class, /* |-------------------------------------------------------------------------- | Filament: Title Attribute |-------------------------------------------------------------------------- | | Point to another field or Attribute to change the | computed record title provided in filament. | */ 'recordTitleAttribute' => 'title', /* |-------------------------------------------------------------------------- | Filament: Label |-------------------------------------------------------------------------- | | If you don't need to support multiple languages you can | globally change the model label below. If you do, | you should rather change the translation files. | */ 'modelLabel' => 'Page', /* |-------------------------------------------------------------------------- | Filament: Plural Label |-------------------------------------------------------------------------- | | If you don't need to support multiple languages you can | globally change the plural label below. If you do, | you should rather change the translation files. | */ 'pluralLabel' => 'Pages', 'navigation' => [ /* |-------------------------------------------------------------------------- | Filament: Navigation Icon |-------------------------------------------------------------------------- | | If you don't need to support multiple languages you can | globally change the navigation icon below. If you do, | you should rather change the translation files. | */ 'icon' => 'heroicon-o-document', /* |-------------------------------------------------------------------------- | Filament: Navigation Group |-------------------------------------------------------------------------- | | If you don't need to support multiple languages you can | globally change the navigation group below. If you do, | you should rather change the translation files. | */ 'group' => 'content', /* |-------------------------------------------------------------------------- | Filament: Navigation Group |-------------------------------------------------------------------------- | | If you don't need to support multiple languages you can | globally change the navigation sort below. If you do, | you should rather change the translation files. | */ 'sort' => null, ] ], /* |-------------------------------------------------------------------------- | Templates |-------------------------------------------------------------------------- | | Add your own Templates implementing FilamentPageTemplate::class | below. They will appear in the Template selection, | and persisted to the data column. | */ 'templates' => [ DefaultTemplate::class, ], /* |-------------------------------------------------------------------------- | Renderer |-------------------------------------------------------------------------- | | If you want to use the Rendering functionality, you can create your | own Renderer here. Take the available Renderers for reference. | See FilamentPageController for recommended usage. | | Available Renderers: | - SimplePageRenderer: | Renders everything to the defined layout below. | - AtomicDesignPageRenderer: | More opinionated Renderer to be used with Atomic Design. | | To use the renderer, Add a Route for the exemplary FilamentPageController: | | Route::get('/{filamentPage}', [FilamentPageController::class, 'show']); | | To route the homepage, you could add a data.is_homepage | field and query it in a controller. | */ 'renderer' => SimplePageRenderer::class, /* |-------------------------------------------------------------------------- | Simple Page Renderer: Default Layout |-------------------------------------------------------------------------- | | Only applicable to the SimplePageRenderer. | */ 'default_layout' => 'layouts.app', ];
使用方法
在Filament中
运行安装命令后,您将在Filament管理员中找到一个新页面资源。
模板
此包使用Dennis Koch (pxlrbt)提出的基于模板的表单概念。您可以在他的Filament技巧中了解更多关于这个一般想法的细节。
您将找到一个基本的页面模板。通过创建和选择您自己的模板,您可以完全自定义您的页面。
要创建您自己的模板,请实现Beier\FilamentPages\Contracts\FilamentPageTemplate
<?php namespace App\Filament\FilamentPageTemplates; use Beier\FilamentPages\Contracts\FilamentPageTemplate; use Filament\Forms\Components\Card; use Filament\Forms\Components\RichEditor; class MyTemplate implements FilamentPageTemplate { public static function title(): string { return 'My Template'; } public static function schema(): array { return [ Card::make() ->schema([ RichEditor::make('content') ]), ]; } }
最后,在config/filament-pages.php
中注册您的模板
<?php return [ 'templates' => [ // \Beier\FilamentPages\Filament\FilamentPageTemplates\DefaultTemplate::class, \App\Filament\FilamentPageTemplates\MyTemplate::class, ], ];
您的模板将出现在模板选择中,并相应地渲染模式。
自定义页面资源
扩展页面资源的推荐方法是重写
FilamentPageResource::insertBeforePrimaryColumnSchema
FilamentPageResource::insertAfterPrimaryColumnSchema
FilamentPageResource::insertBeforeSecondaryColumnSchema
FilamentPageResource::insertAfterSecondaryColumnSchema
在您的自定义PageResource类中,扩展Beier\FilamentPages\Filament\Resources\FilamentPageResource
。
您将在配置文件中找到大多数常见配置选项。
<?php namespace App\Filament\Resources; use Beier\FilamentPages\Filament\Resources\FilamentPageResource; use Filament\Resources\Form; use Filament\Resources\Table; use Filament\Forms\Components\Toggle; use Filament\Forms\Components\TextInput; class PageResource extends FilamentPageResource { /** * Recommended: Insert Fields at the beginning of the primary column. */ public static function insertBeforePrimaryColumnSchema(): array { return [ Toggle::make('is_homepage'), ]; } /** * Recommended: Insert Fields at the end of the primary column. */ public static function insertAfterPrimaryColumnSchema(): array { return [ TextInput::make('author'), ]; } /** * Recommended: Insert Fields at the beginning of the secondary column. (sidebar) */ public static function insertBeforeSecondaryColumnSchema(): array { return [ Toggle::make('is_homepage'), ]; } /** * Recommended: Insert Fields at the end of the secondary column. (sidebar) */ public static function insertAfterSecondaryColumnSchema(): array { return [ SEO::make(), ]; } /** * Not Recommended: Override the whole form */ /** public static function form(Form $form): Form { return $form ->schema([ // ]); } */ /** * Not Recommended: Override the whole table */ /** public static function table(Table $table): Table { return $table ->columns([ // ]); } */ }
然后,在config/filament-pages.php
中注册您的类
<?php use App\Filament\Resources\PageResource; return [ 'filament' => [ 'resource' => PageResource::class, ], ]
示例
使用laravel-filament-seo进行使用
-
创建
app/Models/FilamentPage.php
<?php namespace App\Models; use Beier\FilamentPages\Models\FilamentPage as BeierFilamentPage; use RalphJSmit\Laravel\SEO\Support\HasSEO; use RalphJSmit\Laravel\SEO\Support\SEOData; class FilamentPage extends BeierFilamentPage { use HasSEO; public function getDynamicSEOData(): SEOData { return new SEOData( title: $this->title, ); } }
-
创建
app/Filament/Resources/PageResource.php
<?php namespace App\Filament\Resources; use RalphJSmit\Filament\SEO\SEO; use Beier\FilamentPages\Filament\Resources\FilamentPageResource; class PageResource extends FilamentPageResource { public static function insertAfterSecondaryColumnSchema(): array { return [ SEO::make(), ]; } }
-
在
config/filament-pages.php
中定义模型和资源return [ 'filament' => [ 'resource' => \App\Filament\Resources\PageResource::class, 'model' => \App\Models\FilamentPage::class, ], ];
-
如有必要,清除应用程序缓存以使服务定位器加载您的资源
$ php artisan cache:clear
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志
贡献
有关详细信息,请参阅贡献指南
安全漏洞
有关如何报告安全漏洞的信息,请参阅我们的安全策略
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件