HomeController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\UsefulLink;
  4. use App\Models\Configuration;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. class HomeController extends Controller
  8. {
  9. public function __construct()
  10. {
  11. $this->middleware('auth');
  12. }
  13. /** Show the application dashboard. */
  14. public function index(Request $request)
  15. {
  16. $usage = Auth::user()->creditUsage();
  17. $credits = Auth::user()->Credits();
  18. $bg = "";
  19. $boxText = "";
  20. $unit = "";
  21. // START OF THE TIME-REMAINING-BOX
  22. if ($credits > 0.01 and $usage > 0)
  23. {
  24. $days = number_format(($credits * 30) / $usage, 2, '.', '');
  25. $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', '');
  26. // DEFINE THE BACKGROUND COLOR
  27. if ($days >= 15)
  28. {
  29. $bg = "success";
  30. }
  31. elseif ($days >= 8 && $days <= 14)
  32. {
  33. $bg = "warning";
  34. }
  35. elseif ($days <= 7)
  36. {
  37. $bg = "danger";
  38. }
  39. // DEFINE WETHER DAYS OR HOURS REMAIN
  40. if ($days < "1")
  41. {
  42. if ($hours < "1")
  43. {
  44. $boxText = 'You ran out of Credits ';
  45. }
  46. else
  47. {
  48. $boxText = $hours;
  49. $unit = "hours";
  50. }
  51. }
  52. else
  53. {
  54. $boxText = number_format($days, 0);
  55. $unit = "days";
  56. }
  57. }
  58. // RETURN ALL VALUES
  59. return view('home')->with([
  60. 'useage' => $usage,
  61. 'useful_links' => UsefulLink::all()->sortBy('id'),
  62. 'bg' => $bg,
  63. 'boxText' => $boxText,
  64. 'unit' => $unit
  65. ]);
  66. }
  67. }