如何在十月CMS中选择多种颜色



我正在使用October cms平台开发一个购物车系统。某些产品项目将有多种颜色。

但是使用默认的颜色选择器,我不知道如何选择多种颜色。我在互联网上搜索了所有内容,但没有得到我的情况的答案。任何帮助将不胜感激。

嗯可能只是使用中继器并在其中添加颜色选择器,以便您可以添加N no. of colour[这是简单的方法,但如果您在搜索中使用此属性/值,那么这不是首选方式使用mm relation然后]

它将作为json存储在数据库字段中,您可以将其添加到模型中

namespace  HardikSatasiyaPluginModels;
use Model;
class Product extends Model
{
protected $jsonable = ['product_colors']; 
....

图式

Schema::create('hardiksatasiya_pluginname_products', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name')->nullable();
$table->string('slug')->index();
$table->text('product_colors')

您可以像这样定义中继器。

product_colors:
type: repeater
form:
fields:
color:
label: Background
type: colorpicker

由于$model->product_colors将拥有一系列像他这样的colors

$model->product_colors <=> [ 0 => [ 'color' => 'red'], 1 => [ 'color' => 'blue'] ]

要访问值,您可以直接使用 $model->product_colors 它将array so you can loop through it.

// $model->product_colors[0]->color -> red
// $model->product_colors[1]->color -> blue

如有任何疑问,请发表评论。

最新更新