helpers.php 1.2 KB

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