HeaderData.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Middleware\Shop;
  3. use App\Helpers\Utils;
  4. use App\Services\CallApiService;
  5. use Closure;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Route;
  8. class HeaderData
  9. {
  10. /**
  11. * Handle an incoming request.
  12. *
  13. * @param \Illuminate\Http\Request $request
  14. * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
  15. * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
  16. */
  17. public function handle(Request $request, Closure $next)
  18. {
  19. $mainMenuPerm = Utils::getProMainMenu();
  20. $mainMenuPermPage = collect($mainMenuPerm['Page'])->filter(function ($menu) {
  21. return $menu['Sort'] === 'primary';
  22. })->toArray();
  23. $topMenuPermPage = collect($mainMenuPerm['Page'])->filter(function ($menu) {
  24. return $menu['Sort'] === 'top';
  25. })->toArray();
  26. $mainMenuList = Utils::formatMenuList($mainMenuPermPage, 'MenuCode');
  27. $topMenuList = Utils::formatMenuList($topMenuPermPage, 'MenuCode');
  28. $headerPart = app(CallApiService::class)->callApi([
  29. 'url' => 'list-type1-book',
  30. 'data' => [
  31. 'Book' => [
  32. [
  33. 'QueryVars' => [
  34. 'QueryName' => 'pro:shop/wish',
  35. 'SubSimpleFilter' => "image_type = 'thumb'",
  36. 'IsntPagination' => true,
  37. ],
  38. 'PageVars' => [
  39. 'Limit' => 100000
  40. ]
  41. ],
  42. [
  43. 'QueryVars' => [
  44. 'QueryName' => 'point2u::pro:shop/cart',
  45. 'SubSimpleFilter' => "image_type = 'thumb'",
  46. 'IsntPagination' => true,
  47. ],
  48. 'PageVars' => [
  49. 'Limit' => 100000
  50. ]
  51. ]
  52. ]
  53. ],
  54. ]);
  55. $currentRoute = Route::currentRouteName();
  56. view()->share('mainMenuList', $mainMenuList);
  57. view()->share('topMenuList', $topMenuList);
  58. view()->share('headerPart', $headerPart);
  59. view()->share('currentRoute', $topMenuPermPage);
  60. return $next($request);
  61. }
  62. }