HomeController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 = 0;
  17. $bg="";
  18. $boxText="";
  19. $unit = "";
  20. foreach (Auth::user()->servers as $server){
  21. $usage += $server->product->price;
  22. }
  23. // START OF THE TIME-REMAINING-BOX
  24. if(Auth::user()->Credits() > 0.01 and $usage > 0){
  25. $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.','');
  26. $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.','');
  27. // DEFINE THE BACKGROUND COLOR
  28. if($days >= 15){
  29. $bg = "success";
  30. }elseif ($days >= 8 && $days <= 14){
  31. $bg = "warning";
  32. }elseif ($days <= 7){
  33. $bg = "danger";
  34. }
  35. // DEFINE WETHER DAYS OR HOURS REMAIN
  36. if($days < "1"){
  37. if($hours < "1"){
  38. $boxText = 'You ran out of Credits ';
  39. }
  40. else{
  41. $boxText = $hours;
  42. $unit = "hours";
  43. }
  44. }else{
  45. $boxText = number_format($days,0);
  46. $unit = "days";
  47. }
  48. }
  49. // RETURN ALL VALUES
  50. return view('home')->with([
  51. 'useage' => $usage,
  52. 'useful_links' => UsefulLink::all()->sortBy('id'),
  53. 'bg' => $bg,
  54. 'boxText' => $boxText,
  55. 'unit' => $unit
  56. ]);
  57. }
  58. }