You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1KB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Product;
  4. use Framework\Routing\Router;
  5. class ShowHomePageController
  6. {
  7. public function handle(Router $router)
  8. {
  9. $cache = app('cache');
  10. $products = Product::all();
  11. $productsWithRoutes = array_map(function ($product) use ($router, $cache) {
  12. $key = "route-for-product-{$product->id}";
  13. if (!$cache->has($key)) {
  14. $cache->put($key, $router->route('view-product', ['product' => $product->id]));
  15. }
  16. $product->route = $cache->get($key);
  17. return $product;
  18. }, $products);
  19. // app('queue')->push(
  20. // fn($name) => app('logging')->info("Hello {$name}"),
  21. // 'Chris',
  22. // );
  23. // app('logging')->info('Send a task into the background');
  24. // app('queue')->push(
  25. // fn($name) => app('email')
  26. // ->to('cgpitt@gmail.com')
  27. // ->text("Hello {$name}")
  28. // ->send(),
  29. // 'Chris',
  30. // );
  31. return view('home', [
  32. 'products' => $productsWithRoutes,
  33. ]);
  34. }
  35. }

Powered by TurnKey Linux.