helpers.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tatu
  5. * Date: 6/23/20
  6. * Time: 12:10 AM
  7. */
  8. use App\Models\AppSession;
  9. if(!function_exists('get_current_session')) {
  10. function get_current_session(){
  11. return AppSession::where('session_key', request()->cookie('sessionKey'))->first();
  12. }
  13. }
  14. if(!function_exists('friendly_date_time')) {
  15. function friendly_date_time($value, $includeTime = true) {
  16. if(!$value || empty($value)) return "-";
  17. try {
  18. $result = strtotime($value);
  19. $result = date("j M o" . ($includeTime ? ", H:i" : ""), $result);
  20. return $result;
  21. }
  22. catch (Exception $e) {
  23. return $value;
  24. }
  25. }
  26. }
  27. if(!function_exists('friendly_month')) {
  28. function friendly_month($value) {
  29. if(!$value || empty($value)) return "-";
  30. try {
  31. $result = strtotime($value);
  32. $result = date("M o", $result);
  33. return $result;
  34. }
  35. catch (Exception $e) {
  36. return $value;
  37. }
  38. }
  39. }
  40. if(!function_exists('time_in_minsec')) {
  41. function time_in_minsec($value, $default = '0s') {
  42. if(!$value || empty($value)) return $default;
  43. $value = intval($value);
  44. $minutes = intval($value / 60);
  45. $seconds = $value % 60;
  46. return "{$minutes}m, {$seconds}s";
  47. }
  48. }