Преглед на файлове

Add selecte to array to

Azam Rezayi преди 4 години
родител
ревизия
aee98cacd4
променени са 2 файла, в които са добавени 12 реда и са изтрити 22 реда
  1. 6 16
      packages/product/src/Http/Controllers/ProductController.php
  2. 6 6
      packages/product/src/js/product.js

+ 6 - 16
packages/product/src/Http/Controllers/ProductController.php

@@ -201,26 +201,16 @@ class ProductController extends Controller
     public function uploadValAttribute(Request $request)
     {
         $productID = $request->productID;
+//       dd( [$request->val_attribute]);
         $product = Product::where('id', $productID)->first();
         $attributes = [];
-        foreach ( $request->val_attribute as $attr_id => $values ){
-            $attributes[$attr_id] = ['val_attribute' => $values];
+        foreach ( [$request->val_attribute] as $attr_id => $values ){
+            $attributes[ $attr_id ] = ['val_attribute' => $values];
 
         }
-//        dd( $attributes );
-        $product->attributes()->sync( $attributes );
- dd( $attributes );
-        foreach ( $request->val_attribute as $attr_id => $values ){
-            $values = array_values( $values );
-            echo $attr_id . ' ';
-            var_dump( $values );
-            echo "<hr>";
-
-        }
-        dd();
-        $product->attributes()->sync($request->val_attribute);
-        dd(1);
-
+//        dd($attributes);
+        $product->attributes()->sync($attributes);
+dd($attributes);
 //        if ((!$attributables->attribute_id='attribute_id' && !$attributables->attributable_id='attributable_id')){
 //            foreach ($info as $item){
 //                $data = [

+ 6 - 6
packages/product/src/js/product.js

@@ -23,7 +23,7 @@ $(document).on('click', '.attribute_creator', function () {
         new_select.find('select').removeClass();
         new_select.find('select').addClass('newSelectItem');
         $('div.added_attribute:last').after( new_select.html() );
-        $('div.added_attribute:last').show().find('select').attr('name', 'val_attribute[' + attr_id + '][]');
+        $('div.added_attribute:last').show().find('select').attr('name', 'val_attribute[' + attr_id + ']'+'[]');
         $('#saveItemAttribute').show();
         $(".added_attribute select").select2({
             tags: true
@@ -50,11 +50,11 @@ $(document).on('click', '.attribute_creator', function () {
             processData: false,
             contentType: false,
             success: function(operate) {
-                // if (operate.status == 200){
-                //     swal(operate.msg);
-                // }else {
-                //     swal(operate.msg);
-                // }
+                if (operate.status == 200){
+                    swal(operate.msg);
+                }else {
+                    swal(operate.msg);
+                }
             }
         });