cube-agency/filament-template
最新稳定版本:v2.0.0
Composer 安装命令:
composer require cube-agency/filament-template
包简介
Template field for Filament
README 文档
README
Template field for Filament, that gives an option to have different fields based on field value or type in one Resource.
Compatibility
| Package Version | Filament Version |
|---|---|
| 1.x | 3.x |
| 2.x | 4.x |
Installation
You can install the package via composer:
composer require cube-agency/filament-template
You can publish the config file with:
php artisan vendor:publish --tag="filament-template-config"
Usage
Add "template" column to your Model/table
$table->string('template');
Create your template by using console command:
php artisan filament-template:create Blog
Add it to config
return [ 'templates' => [ \App\Filament\Templates\BlogTemplate::class, ] ];
At this moment, this could be used by passing url parameter (query string) to create form
class CreatePage extends CreateRecord { public $template; protected $queryString = ['template']; }
and adding this in your Resource
public static function form(Form $form): Form { return $form ->schema([ // ... Hidden::make('template') ->default($this->getTemplate()), Template::make('content') ->template($this->resolveTemplate()), ]); } protected function resolveTemplate() { return app($this->getTemplate()); } protected function getTemplate() { if (property_exists($this, 'template')) { return $this->template; } return $this->getRecord()->getAttribute('template'); }
Override create action to show modal with template select
public function getActions(): array { return [ Action::make('create') ->form($this->actionForm()) ->action(function (array $data): void { $parameters = http_build_query($data); $this->redirect(static::$resource::getUrl('create') . '?' . $parameters); }) ]; } protected function getTemplates(): Collection { return collect(config('filament-template.templates'))->mapWithKeys(function ($template) { $templateName = explode('\\', $template); return [$template => end($templateName)]; }); } protected function actionForm(): array { return [ Select::make('template') ->label('Template') ->options($this->getTemplates()) ->required(), ]; }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 682
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-03