mau bertanya terkait laravel mambuat product id, color multiple image, size stock

DB::beginTransaction();
            try {
                //CHECK DATA CUSTOMER BERDASARKAN EMAIL


                    $product = Product::create([
                        'name' => $request->name,
                        'slug' => Str::random(10),
                        'price' => $request->price,
                        'sku' => Str::random(4),
                        'status' => $request->status,
                        'weight' => $request->weight,
                        'description' => $request->description,
                    ]);
     
                if ($product) {
                                        
                    if($files = $request->file('image')){
            
                        foreach($files as $file){
                            $name = rand(1,50).'.'.$file->getClientOriginalExtension();
                            $file->move(public_path('images'), $name);
                            $images[] = $name;
                        }
                    }

                    foreach($request['color'] as $key => $val)
                    {
                        ProductColor::create([
                            'color' => $val,
                            'product_id' => $product->id,
                            'image' => json_encode($images),
                            'size' => $request['size'][$key],
                            'stock' => $request['stock'][$key],
                        ]);
                    }
                    
                }
                // dd($product, $Color);

    
                DB::commit();
avatar carengibran_google
@carengibran_google

1 Kontribusi 0 Poin

Dipost 4 bulan yang lalu

Tanggapan

jangan hanya copy-paste kode ya. Tapi jelaskan apa yang kamu mau dan apa masalah sekarang

Pertanyaan kamu tidak jelas, coba dijelaskan lebih baik

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban