helpers.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. if (! function_exists('ossUrl')) {
  3. /*
  4. * 如果url 不是http或https开头,则加上oss的域名
  5. * @param string $path 路径
  6. */
  7. function ossUrl($path) {
  8. if (empty($path)) {
  9. return '';
  10. }
  11. if (strpos($path, 'http') === 0 || strpos($path, 'https') === 0) {
  12. return $path;
  13. }
  14. return env('OSS_HOST').'/'. $path;
  15. }
  16. }
  17. if (! function_exists('getBreadcrumb')) {
  18. function getBreadcrumb($id, $data, $path = []) {
  19. foreach ($data as $item) {
  20. // 如果当前项的 id 匹配,将其 title 加入路径
  21. if ($item['id'] == $id) {
  22. $path[] = $item['title'];
  23. return $path;
  24. }
  25. // 如果有子节点,递归查找
  26. if (!empty($item['children'])) {
  27. $result = getBreadcrumb($id, $item['children'], $path);
  28. if (!empty($result)) {
  29. // 如果找到匹配的子节点,将当前项的 title 加入路径
  30. array_unshift($result, $item['title']);
  31. return $result;
  32. }
  33. }
  34. }
  35. // 如果没有找到匹配的 id,返回空数组
  36. return [];
  37. }
  38. }