GetSeoInfo.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Http\Middleware;
  3. use View;
  4. use App\Services\Content\NavigationService;
  5. use Closure;
  6. class GetSeoInfo
  7. {
  8. protected $navigationService;
  9. /**
  10. * GetSeoInfo constructor.
  11. * @param NavigationService $navigationService
  12. */
  13. public function __construct(NavigationService $navigationService)
  14. {
  15. $this->navigationService = $navigationService;
  16. }
  17. /**
  18. * Handle an incoming request.
  19. *
  20. * @param \Illuminate\Http\Request $request
  21. * @param \Closure $next
  22. * @return mixed
  23. */
  24. public function handle($request, Closure $next)
  25. {
  26. if (!str_contains($request->route()->getPrefix(), 'admin')) {
  27. $page_seo = $this->navigationService->getSeo($request->route());
  28. if (!$page_seo) {
  29. $page_seo = $this->getCustomPageSeo($request->route()->getName());
  30. }
  31. View::share('page_seo', $page_seo);
  32. }
  33. return $next($request);
  34. }
  35. private function getCustomPageSeo($url_name)
  36. {
  37. $custom_arr = array(
  38. 'person.*' => array(
  39. 'title' => '个人会员中心-{#site_name}',
  40. 'keywords' => '',
  41. 'description' => ''
  42. ), //个人中心
  43. 'com.*' => array(
  44. 'title' => '企业会员中心-{#site_name}',
  45. 'keywords' => '',
  46. 'description' => ''
  47. ), //企业中心
  48. 'service.*'=>array(
  49. 'title' => '企业会员中心-{#site_name}',
  50. 'keywords' => '',
  51. 'description' => ''
  52. ),//企业中心======》会员套餐
  53. 'jobs.*'=>array(
  54. 'title' => '企业会员中心-{#site_name}',
  55. 'keywords' => '',
  56. 'description' => ''
  57. ),//企业中心======》职位管理
  58. 'resume.*'=>array(
  59. 'title' => '企业会员中心-{#site_name}',
  60. 'keywords' => '',
  61. 'description' => ''
  62. ),//企业中心======》简历管理
  63. 'jobfair.*'=>array(
  64. 'title' => '企业会员中心-{#site_name}',
  65. 'keywords' => '',
  66. 'description' => ''
  67. ),//企业中心======》招聘会管理
  68. 'help.search' => array(
  69. 'title' => '帮助-{#site_name}',
  70. 'keywords' => '',
  71. 'description' => ''
  72. ),
  73. 'register.*' => array(
  74. 'title' => '会员注册-{#site_name}',
  75. 'keywords' => '',
  76. 'description' => ''
  77. ), //注册
  78. 'login.*' => array(
  79. 'title' => '会员登录-{#site_name}',
  80. 'keywords' => '',
  81. 'description' => ''
  82. ), //登陆
  83. 'password.request' => array(
  84. 'title' => '忘记密码-{#site_name}',
  85. 'keywords' => '',
  86. 'description' => ''
  87. ), //忘记密码
  88. 'password.reset' => array(
  89. 'title' => '重置密码-{#site_name}',
  90. 'keywords' => '',
  91. 'description' => ''
  92. ), //重置密码
  93. );
  94. foreach ($custom_arr as $key => $value) {
  95. if (strpos($key, '*')!==false) {
  96. $key=str_replace('*', '', $key);
  97. if (strpos($url_name, $key)!==false) {
  98. return $value;
  99. }
  100. } else {
  101. if ($key == $url_name) {
  102. return $value;
  103. }
  104. }
  105. }
  106. return false;
  107. }
  108. }