/** * @param PropertyUnit $units * @return string * @throws \Exception */ public function destroy(PropertyUnit $units) { if ($units->id) { if ($units->delete()) { return json_encode(['status' => 'oke']); } } return json_encode(['status' => 'noke']); }
/** * @param Product $product * @param PropertyUnit $unit */ protected function prepareProperties(Product $product, PropertyUnit $unit) { $category = $product->mainCategory(); if ($category) { $category->load(['propertyGroups', 'propertyGroups.translations', 'properties', 'properties.translations']); $product->propertyGroups = $category->propertyGroups; $product->propertyProperties = $category->properties->groupBy('group_id'); foreach ($product->propertyGroups as $group) { if (!$product->propertyProperties->has($group->id)) { //make sure we can add to empty groups $product->propertyProperties->put($group->id, new Collection()); } } $product->propertyUnits = $unit->with('translations')->get()->keyBy('id'); $propertyIds = $category->properties->lists('id')->toArray(); if (count($propertyIds)) { $product->propertyOptions = PropertyOption::with(['translations'])->whereIn('property_id', $propertyIds)->get()->groupBy('property_id'); $product->propertyOptions = $product->propertyOptions->map(function ($item) { return $item->keyBy('id'); }); } else { $product->propertyOptions = new Collection(); } $product->hasMainCategory = true; $product->setRelation('properties', $product->properties->keyBy('property_id')); } }
protected function baseProperties() { factory(PropertyUnit::class)->times(35)->create(); $units = PropertyUnit::all(); foreach (Category::all() as $category) { $groups = factory(PropertyGroup::class)->times(4)->create(['category_id' => $category->id]); factory(Property::class, 'numeric')->times(4)->create(['unit_id' => $units->random(1)->id, 'group_id' => $groups->random(1)->id, 'category_id' => $category->id]); factory(Property::class, 'boolean')->times(5)->create(['group_id' => $groups->random(1)->id, 'category_id' => $category->id]); factory(Property::class, 'float')->times(1)->create(['group_id' => $groups->random(1)->id, 'category_id' => $category->id]); factory(Property::class, 'string')->times(3)->create(['group_id' => $groups->random(1)->id, 'category_id' => $category->id]); factory(Property::class, 'options')->times(3)->create(['group_id' => $groups->random(1)->id, 'category_id' => $category->id])->each(function ($property) { factory(PropertyOption::class)->times(rand(4, 10))->create(['property_id' => $property->id]); }); } }