vonsogt / template-operation
为 soufiene-slimi/laravel-form-template 提供的 Backpack 接口
Requires
- backpack/crud: ^4.1.0
- soufiene-slimi/laravel-form-template: ^1.0
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3|~4
- phpunit/phpunit: ^8.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-09-08 11:21:49 UTC
README
为您的 Backpack CRUD 添加了 soufiene-slimi/laravel-form-template
接口,以便管理员可以
- 将表单保存为模板;
- 在创建新表单时应用这些模板;
soufiene-slimi/laravel-form-template
允许您保存一些表单模板,以便您可以在需要时应用它们。这个工具的作用是避免反复填写一些相同的输入,这些输入大多数时候具有相同的值,或者根据用户的选择应用一些模板。
当使用此操作时,在列表视图中会在创建按钮旁边显示另一个按钮。点击该按钮将打开另一个页面,允许管理员为该条目创建模板。
安装
步骤 1. 需求包
composer require soufiene-slimi/template-operation
如果尚未安装,这将自动安装 soufiene-slimi/laravel-form-template
。
步骤 2. 迁移 soufiene-slimi/laravel-form-template
表
php artisan migrate
步骤 3. 在您的 CrudController 中使用操作特性
<?php namespace App\Http\Controllers\Admin; use Backpack\CRUD\app\Http\Controllers\CrudController; class InvoiceCrudController extends CrudController { use \SoufieneSlimi\TemplateOperation\TemplateOperation;
对于复杂的用法,请访问 soufiene-slimi/laravel-form-template 查看完整文档和额外的配置选项。
用法
安装操作后,您需要像在创建操作中一样定义模板字段和验证(如果需要)。
protected function setupTemplateOperation() { $this->crud->setValidation(InvoiceTemplateRequest::class); $this->crud->setOperationSetting('excludedInputs', ['paid']); CRUD::field('title')->type('custom_html')->value('<h1>FXXXX-XXXXXX</h1>')->size(8); CRUD::field('type')->default(3)->size(4); CRUD::field('hr')->type('custom_html')->value('<hr>'); CRUD::field('client')->size(6); CRUD::field('items')->type('repeatable')->fields([ [ 'name' => 'product', 'label' => 'Product', 'type' => 'select2_from_array', 'options' => Product::get(['id', 'name'])->pluck('name', 'id')->toArray(), 'wrapperAttributes' => ['class' => 'form-group col-md-6'], ], [ 'name' => 'quantity', 'label' => 'Quantity', 'type' => 'number', 'wrapperAttributes' => ['class' => 'form-group col-md-3'], 'attributes' => ['step' => 'any'], ], [ 'name' => 'price', 'label' => 'Price', 'type' => 'number', 'wrapperAttributes' => ['class' => 'form-group col-md-3'], 'attributes' => ['step' => 'any'], ], ]); CRUD::field('total') ->label('Total ('.config('settings.currency').')') ->type('number') ->size(5) ->attributes(['readonly' => 'true']); CRUD::field('paid')->type('number')->attributes(['step' => 'any'])->size(5); CRUD::field('wallet')->default(config('settings.default_wallet'))->size(2); }
如果您需要自定义一些设置,您需要在 config\backpack\crud.php
文件中添加操作设置。
'operations' => [ /* * Template Operation */ 'template' => [ // The cards color // Available colors: bg-blue, bg-green, bg-purple, bg-orange, bg-red 'cardsClass' => 'bg-orange', // How many cards per row 'cardsPerRow' => 3, // The card icon 'cardIcon' => '<i class="las la-pen-alt"></i>', // Excluded columns 'excludedInputs' => ['status_id'] ], ]
请注意,这些是全局操作设置,意味着这些设置将应用于所有模板操作,但您仍然可以在 EntityCrudController 中通过在 setupTemplateOperation 函数中使用
$this->crud->setOperationSetting('key', value);
定义或覆盖这些设置。
截图
模板列表
添加新模板
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
请参阅 CONTRIBUTING 以获取详细信息和工作清单。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 soufiene.slimi@mail.com 而不是使用问题跟踪器。
致谢
许可
MIT。有关更多信息,请参阅 许可文件。