HomeController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $days = number_format(($credits*30)/$usage,2,'.','');
  24. $hours = number_format($credits/($usage/30/24),2,'.','');
  25. // DEFINE THE BACKGROUND COLOR
  26. if($days >= 15){
  27. $bg = "success";
  28. }elseif ($days >= 8 && $days <= 14){
  29. $bg = "warning";
  30. }elseif ($days <= 7){
  31. $bg = "danger";
  32. }
  33. // DEFINE WETHER DAYS OR HOURS REMAIN
  34. if($days < "1"){
  35. if($hours < "1"){
  36. $boxText = 'You ran out of Credits ';
  37. }
  38. else{
  39. $boxText = $hours;
  40. $unit = "hours";
  41. }
  42. }else{
  43. $boxText = number_format($days,0);
  44. $unit = "days";
  45. }
  46. }
  47. // RETURN ALL VALUES
  48. return view('home')->with([
  49. 'useage' => $usage,
  50. 'useful_links' => UsefulLink::all()->sortBy('id'),
  51. 'bg' => $bg,
  52. 'boxText' => $boxText,
  53. 'unit' => $unit
  54. ]);
  55. }
  56. }