helpers.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. use Illuminate\Support\MessageBag;
  3. if (!function_exists('admin_path')) {
  4. /**
  5. * Get admin path.
  6. *
  7. * @param string $path
  8. *
  9. * @return string
  10. */
  11. function admin_path($path = '')
  12. {
  13. return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
  14. }
  15. }
  16. if (!function_exists('admin_url')) {
  17. /**
  18. * Get admin url.
  19. *
  20. * @param string $path
  21. * @param mixed $parameters
  22. * @param bool $secure
  23. *
  24. * @return string
  25. */
  26. function admin_url($path = '', $parameters = [], $secure = null)
  27. {
  28. if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
  29. return $path;
  30. }
  31. $secure = $secure ?: (config('admin.https') || config('admin.secure'));
  32. return url(admin_base_path($path), $parameters, $secure);
  33. }
  34. }
  35. if (!function_exists('admin_base_path')) {
  36. /**
  37. * Get admin url.
  38. *
  39. * @param string $path
  40. *
  41. * @return string
  42. */
  43. function admin_base_path($path = '')
  44. {
  45. $prefix = '/'.trim(config('admin.route.prefix'), '/');
  46. $prefix = ($prefix == '/') ? '' : $prefix;
  47. $path = trim($path, '/');
  48. if (is_null($path) || strlen($path) == 0) {
  49. return $prefix ?: '/';
  50. }
  51. return $prefix.'/'.$path;
  52. }
  53. }
  54. if (!function_exists('admin_toastr')) {
  55. /**
  56. * Flash a toastr message bag to session.
  57. *
  58. * @param string $message
  59. * @param string $type
  60. * @param array $options
  61. */
  62. function admin_toastr($message = '', $type = 'success', $options = [])
  63. {
  64. $toastr = new MessageBag(get_defined_vars());
  65. session()->flash('toastr', $toastr);
  66. }
  67. }
  68. if (!function_exists('admin_success')) {
  69. /**
  70. * Flash a success message bag to session.
  71. *
  72. * @param string $title
  73. * @param string $message
  74. */
  75. function admin_success($title, $message = '')
  76. {
  77. admin_info($title, $message, 'success');
  78. }
  79. }
  80. if (!function_exists('admin_error')) {
  81. /**
  82. * Flash a error message bag to session.
  83. *
  84. * @param string $title
  85. * @param string $message
  86. */
  87. function admin_error($title, $message = '')
  88. {
  89. admin_info($title, $message, 'error');
  90. }
  91. }
  92. if (!function_exists('admin_warning')) {
  93. /**
  94. * Flash a warning message bag to session.
  95. *
  96. * @param string $title
  97. * @param string $message
  98. */
  99. function admin_warning($title, $message = '')
  100. {
  101. admin_info($title, $message, 'warning');
  102. }
  103. }
  104. if (!function_exists('admin_info')) {
  105. /**
  106. * Flash a message bag to session.
  107. *
  108. * @param string $title
  109. * @param string $message
  110. * @param string $type
  111. */
  112. function admin_info($title, $message = '', $type = 'info')
  113. {
  114. $message = new MessageBag(get_defined_vars());
  115. session()->flash($type, $message);
  116. }
  117. }
  118. if (!function_exists('admin_asset')) {
  119. /**
  120. * @param $path
  121. *
  122. * @return string
  123. */
  124. function admin_asset($path)
  125. {
  126. return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
  127. }
  128. }
  129. if (!function_exists('array_delete')) {
  130. /**
  131. * Delete from array by value.
  132. *
  133. * @param array $array
  134. * @param mixed $value
  135. */
  136. function array_delete(&$array, $value)
  137. {
  138. foreach ($array as $index => $item) {
  139. if ($value == $item) {
  140. unset($array[$index]);
  141. }
  142. }
  143. }
  144. }