如何在单列字段中更新多个json编码数据?

时间:2019-05-21 05:39:45

标签: laravel-5.8

数组:2 [▼   0 =>“ iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AABNq0lEQVR42u3dCZwcVZ3A8Uq6uqu6uqYnx2RykBBCEmIgQCAJSTiUQ1cQEBDUFVRcQVhALg9UUIH1BAVX   1 =>“ iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAACxKgAAsSoBYacs7wAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZAS5CA ]

代码:   $ multi_image = $ request-> file('multi_image');

    if ($multi_image == '') 
    {

            $data[] = 'null';
    }

    else 
    {
            $file = $request->file('multi_image');

                for($i = 0 ; $i< count($file); $i++)
                {
                    $data[]= base64_encode(file_get_contents($file[$i]));

                }
    }



    $sort = $request->input('category_id');
    $order = Category::where('id','=',$sort)->first();



    $item = new Item();
    $item->admin_id = Auth::user()->id;
    $item->category_id = $request->input('category_id');
    $item->category_sort_order = $order->sort_order;
    $item->name = $request->input('name');
    $item->description = $request->input('description');
    $item->image = $image;
    $item->multi_image = json_encode($data);
    // $item->currency = '₹';
    $item->price = $request->input('price');

0 个答案:

没有答案