soufiene-slimi / 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-09 19:09:43 UTC
README
为您的 Backpack CRUDs 添加 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 中使用
$this->crud->setOperationSetting('key', value);
在 setupTemplateOperation 函数中定义或覆盖这些设置。
屏幕截图
模板列表
添加新模板
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
有关详细信息和工作清单,请参阅 CONTRIBUTING。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 soufiene.slimi@mail.com 而不是使用问题跟踪器。
鸣谢
许可证
MIT。有关更多信息,请参阅 许可证文件。