payload['spu_id'] ?? 0; foreach ($input as $id => $items) { $spuSpec = ProductSpuSpec::findOrFail($id); $spuSpecsItems = array_column($spuSpec->items, 'name'); //除去空值 foreach ($items as $key => $item) { if ($item['name'] === '' || $item['value'] === '') { unset($items[$item]); } } //如果删除某个属性,需要判断该属性下是否有sku $nowSpecsItems = array_column($items, 'name'); $diffSpecsItems = array_diff($spuSpecsItems, $nowSpecsItems); foreach ($diffSpecsItems as $name) { if (ProductSku::where('spu_id', $spuId)->where('specs->'.$id, $name)->exists()) { return $this->response()->error(__('admin_message.forms.setting_spu_specs.errors.has_specs', ['name'=>$name])); } } ProductSpuSpec::where('id', $id)->update([ 'items' => $items, ]); } } // return $this->response()->error('Your error message.'); return $this ->response() ->success(__('admin.update_succeeded')) ->refresh(); } /** * Build a form here. */ public function form() { $spuId = $this->payload['spu_id'] ?? null; $spu = ProductSpu::findOrFail($spuId); foreach ($spu->specs as $spec) { $this->table($spec->id, $spec->name, function ($table) { $table->text('name', __('admin_message.forms.setting_spu_specs.table.name')); $table->currency('value', __('admin_message.forms.setting_spu_specs.table.value'))->symbol('¥')->default(0); })->customFormat(function () use ($spec) { return $spec->items; }); } $this->disableResetButton(); } /** * The data of the form. * * @return array */ public function default() { return [ // 'name' => 'John Doe', // 'email' => 'John.Doe@gmail.com', ]; } }