CategoryController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers\Front;
  3. use App\Shop\Categories\Repositories\CategoryRepository;
  4. use App\Shop\Categories\Repositories\Interfaces\CategoryRepositoryInterface;
  5. use App\Http\Controllers\Controller;
  6. class CategoryController extends Controller
  7. {
  8. /**
  9. * @var CategoryRepositoryInterface
  10. */
  11. private $categoryRepo;
  12. /**
  13. * CategoryController constructor.
  14. *
  15. * @param CategoryRepositoryInterface $categoryRepository
  16. */
  17. public function __construct(CategoryRepositoryInterface $categoryRepository)
  18. {
  19. $this->categoryRepo = $categoryRepository;
  20. }
  21. /**
  22. * Find the category via the slug
  23. *
  24. * @param string $slug
  25. * @return \App\Shop\Categories\Category
  26. */
  27. public function getCategory(string $slug)
  28. {
  29. $category = $this->categoryRepo->findCategoryBySlug(['slug' => $slug]);
  30. $repo = new CategoryRepository($category);
  31. $products = $repo->findProducts()->where('status', 1)->all();
  32. return view('front.categories.category', [
  33. 'category' => $category,
  34. 'products' => $repo->paginateArrayResults($products, 20)
  35. ]);
  36. }
  37. }