public function testGetByCategory() { $category = \LaravelItalia\Domain\Category::createFromName('Category'); $category->save(); $this->saveTestArticle(false, false, null, $category); $this->saveTestArticle(true, false, null, $category); $this->assertCount(1, $this->repository->getByCategory($category, 1, true)); $this->assertCount(2, $this->repository->getByCategory($category, 1, false)); }
/** * Salva una nuova categoria sul sito, il cui nome è contenuto in $request. * * @param SaveCategoryRequest $request * @param CategoryRepository $categoryRepository * @return \Illuminate\Http\RedirectResponse */ public function postAdd(SaveCategoryRequest $request, CategoryRepository $categoryRepository) { $category = Category::createFromName($request->get('name')); try { $categoryRepository->save($category); } catch (NotSavedException $e) { return redirect('admin/categories')->with('error_message', 'Impossibile aggiungere la categoria. Riprovare.'); } return redirect('admin/categories')->with('success_message', 'Categoria aggiunta con successo.'); }
private function prepareTestCategory($name) { $category = Category::createFromName($name); return $category; }
private function findOrCreateCategoriesFor($article) { $categories = new Collection(); /* @var CategoryRepository $categoryRepository */ $categoryRepository = app(CategoryRepository::class); foreach ($article['categories'] as $oldCategory) { try { $category = $categoryRepository->findBySlug($oldCategory['slug']); } catch (NotFoundException $e) { $category = Category::createFromName($oldCategory['name']); $categoryRepository->save($category); } $categories->add($category); } return $categories; }