PHP code example of abbotton / dcat-sku-plus
1. Go to this page and download the library: Download abbotton/dcat-sku-plus library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abbotton / dcat-sku-plus example snippets
// app/Admin/Controllers/ProductController.php
protected function form()
{
return Form::make(new Product(), function (Form $form) {
$skuParams = [
// 扩展第一列
[
'name' => '会员价', // table 第一行 title
'field' => 'member_price', // input 的 field_name 名称
'default' => 5, // 默认值
],
// 扩展第二列
];
// 新增时
$form->sku('sku', '生成SKU')->addColumn($skuParams);
// 编辑时
$skuData = []; // 数据结构见附录
$skuString = json_encode($skuData);
$form->sku('sku', '生成SKU')->addColumn($skuParams)->value($skuString);
// 获取提交的数据.
$form->saving(function (Form $form) {
// 拿到SKU数据,按照业务逻辑做响应处理即可。
dd($form->input('sku'));
});
});
}