protected function categories($data) { foreach ($data as $category) { $name = $category->naam; Category::create(['nl' => ['name' => $name], 'en' => ['name' => $name], 'fr' => ['name' => $name], 'de' => ['name' => $name]]); } }
/** * @param Request $request * @return string */ public function removeCategory(Request $request) { $this->validate($request, ['product_id' => 'exists:products,id', 'category_id' => 'exists:product_categories,id']); $product = Product::find($request->get('product_id')); $category = Category::find($request->get('category_id')); $product->load('categories'); $category->load('translations'); if ($product->categories->contains($category->id)) { //is the category the main category or a synonym? if (!$category->original_id) { //we can only have 1 main category and synonyms to that category //so we can do an empty sync here $product->categories()->sync([]); return json_encode(['status' => 'flushed']); } else { $product->categories()->detach($category); return $category; } } return json_encode(['status' => false]); }
protected function relationToTest($product) { $category = new Category(); return new BelongsToMany($category->newQuery(), $product, 'product_categories_pivot', 'product_id', 'category_id', 'test_relation'); }
/** * @param Category $category * @return \Illuminate\Database\Eloquent\Model */ protected function propertyGroup(Category $category) { $group = $category->propertyGroups()->save(new PropertyGroup(['nl' => ['name' => 'andere'], 'en' => ['name' => 'other']])); return $group; }
/** * @param CategorySelection $selection */ public function handle(CategorySelection $selection) { $instance = $selection->newInstance(['account_id' => $this->account->id]); //create selection $this->category->selection()->save($instance); }
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]); }); } }
/** * @param Request $request * @param Category $categories * @return $this */ public function store(Request $request, Category $categories) { $input = translation_input($request); $category = $categories->create($input); return $category->load('translations'); }
/** * @param Request $request * @param AccountManager $manager * @param Category $categories */ public function category(Request $request, AccountManager $manager, Category $categories) { $activate = $request->get('status'); $category = $categories->findOrFail($request->get('category')); if ($activate) { $this->dispatch(new ActivateCategory($category, $manager->account())); } else { $this->dispatch(new DeactivateCategory($category, $manager->account())); } }