GlobalTemplateServiceProvider.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Providers;
  3. use App\Shop\Carts\Repositories\CartRepository;
  4. use App\Shop\Carts\ShoppingCart;
  5. use App\Shop\Categories\Category;
  6. use App\Shop\Categories\Repositories\CategoryRepository;
  7. use App\Shop\Employees\Employee;
  8. use App\Shop\Employees\Repositories\EmployeeRepository;
  9. use Illuminate\Support\Facades\Auth;
  10. use Illuminate\Support\ServiceProvider;
  11. /**
  12. * Class GlobalTemplateServiceProvider
  13. * @package App\Providers
  14. * @codeCoverageIgnore
  15. */
  16. class GlobalTemplateServiceProvider extends ServiceProvider
  17. {
  18. /**
  19. * Register bindings in the container.
  20. *
  21. * @return void
  22. */
  23. public function boot()
  24. {
  25. view()->composer([
  26. 'layouts.admin.app',
  27. 'layouts.admin.sidebar',
  28. 'admin.shared.products'
  29. ], function ($view) {
  30. $view->with('admin', Auth::guard('employee')->user());
  31. });
  32. view()->composer(['layouts.front.app', 'front.categories.sidebar-category'], function ($view) {
  33. $view->with('categories', $this->getCategories());
  34. $view->with('cartCount', $this->getCartCount());
  35. });
  36. /**
  37. * breadcumb
  38. */
  39. view()->composer([
  40. "layouts.admin.app"
  41. ], function ($view) {
  42. $breadcumb = [
  43. ["name" => "Dashboard", "url" => route("admin.dashboard"), "icon" => "fa fa-dashboard"],
  44. ];
  45. $paths = request()->segments();
  46. if (count($paths) > 1) {
  47. foreach ($paths as $key => $pah) {
  48. if ($key == 1)
  49. $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
  50. elseif ($key == 2)
  51. $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[1] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
  52. }
  53. }
  54. $view->with(
  55. [
  56. "breadcumbs" => $breadcumb
  57. ]
  58. );
  59. });
  60. view()->composer(['layouts.front.category-nav'], function ($view) {
  61. $view->with('categories', $this->getCategories());
  62. });
  63. }
  64. /**
  65. * Get all the categories
  66. *
  67. */
  68. private function getCategories()
  69. {
  70. $categoryRepo = new CategoryRepository(new Category);
  71. return $categoryRepo->listCategories('name', 'asc', 1)->whereIn('parent_id', [1]);
  72. }
  73. /**
  74. * @return int
  75. */
  76. private function getCartCount()
  77. {
  78. $cartRepo = new CartRepository(new ShoppingCart);
  79. return $cartRepo->countItems();
  80. }
  81. /**
  82. * @param Employee $employee
  83. * @return bool
  84. */
  85. private function isAdmin(Employee $employee)
  86. {
  87. $employeeRepo = new EmployeeRepository($employee);
  88. return $employeeRepo->hasRole('admin');
  89. }
  90. }