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 = 0;
  17. $bg="";
  18. $boxText="";
  19. $unit = "";
  20. foreach (Auth::user()->servers as $server){
  21. $usage += $server->product->price;
  22. }
  23. if(Auth::user()->Credits() > 0.01 and $usage > 0){
  24. $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.','');
  25. $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.','');
  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. if($days < "1"){
  34. if($hours < "1"){
  35. $boxText = 'You ran out of Credits ';
  36. }
  37. else{
  38. $boxText = $hours;
  39. $unit = "hours";
  40. }
  41. }else{
  42. $boxText = number_format($days,0);
  43. $unit = "days";
  44. }
  45. }
  46. return view('home')->with([
  47. 'useage' => $usage,
  48. 'useful_links' => UsefulLink::all()->sortBy('id'),
  49. 'bg' => $bg,
  50. 'boxText' => $boxText,
  51. 'unit' => $unit
  52. ]);
  53. }
  54. }