diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 50c4fc5e..7a58dc3b 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -251,7 +251,7 @@ class UserController extends Controller return ' ' . $user->credits(); }) ->addColumn('usage', function (User $user) { - return ' ' . $user->creditUsage(); + return ' ' . $user->creditUsage(). ' ('.$user->outOfCredits().')'; }) ->addColumn('verified', function (User $user) { return $user->getVerifiedStatus(); diff --git a/app/Models/User.php b/app/Models/User.php index 9c1d8568..c4c2a71d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -80,9 +80,9 @@ class User extends Authenticatable implements MustVerifyEmail */ protected $casts = [ 'email_verified_at' => 'datetime', - 'last_seen' => 'datetime', - 'credits' => 'float', - 'server_limit' => 'float', + 'last_seen' => 'datetime', + 'credits' => 'float', + 'server_limit' => 'float', ]; /** @@ -242,6 +242,26 @@ class User extends Authenticatable implements MustVerifyEmail return number_format($usage, 2, '.', ''); } + + /** + * @description Returns the Users "out of Credits" time + * + * @return string + */ + public function outOfCredits() + { + $usage = $this->creditUsage(); + $credits = $this->credits; + $timeLeft = number_format(($credits * 30) / $usage); + $unit = "days"; + + if ($timeLeft < 1) { + $timeLeft = number_format(($credits * 30) / $usage * 24, 2); + $unit = "hours"; + } + return $timeLeft . " " . $unit; + } + /** * @return array|string|string[] */ diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 885b1c31..2e5704d0 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -46,7 +46,7 @@