【问题标题】:How select multiple colors in october cms如何在 10 月 cms 中选择多种颜色
【发布时间】:2018-11-12 10:10:49
【问题描述】:

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

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

【问题讨论】:

    标签: php octobercms octobercms-backend


    【解决方案1】:

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

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

    namespace  HardikSatasiya\Plugin\Models;
    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
    

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

    【讨论】:

    • 很高兴看到它对您有所帮助 :)
    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 2021-01-07
    • 2016-08-07
    • 2021-10-09
    • 2014-12-04
    • 2016-05-14
    • 2021-01-23
    相关资源
    最近更新 更多