stats overview
This commit is contained in:
47
app/Filament/Widgets/StatsOverview.php
Normal file
47
app/Filament/Widgets/StatsOverview.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Models\Log;
|
||||||
|
use App\Models\Meta;
|
||||||
|
use App\Models\User;
|
||||||
|
use DB;
|
||||||
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||||
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||||
|
|
||||||
|
class StatsOverview extends BaseWidget
|
||||||
|
{
|
||||||
|
protected function getStats(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Stat::make('Total Users', $this->getUser()),
|
||||||
|
Stat::make('Paid Users', $this->getUserPaid()),
|
||||||
|
Stat::make('Logs Count', $this->getLogsCount()),
|
||||||
|
Stat::make('Total Mailbox', $this->getTotalMailbox()),
|
||||||
|
Stat::make('Emails Received', $this->getTotalEmailsReceived()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
private function getUser(): int
|
||||||
|
{
|
||||||
|
return User::all()->count();
|
||||||
|
}
|
||||||
|
private function getUserPaid(): int
|
||||||
|
{
|
||||||
|
return DB::table('subscriptions')
|
||||||
|
->where(['stripe_status' => 'active'])
|
||||||
|
->distinct('user_id')
|
||||||
|
->count('user_id');
|
||||||
|
}
|
||||||
|
private function getLogsCount(): int
|
||||||
|
{
|
||||||
|
return Log::all()->count();
|
||||||
|
}
|
||||||
|
private function getTotalMailbox(): int
|
||||||
|
{
|
||||||
|
return Meta::select('value')->where(['key' => 'email_ids_created'])->first()->value;
|
||||||
|
}
|
||||||
|
private function getTotalEmailsReceived(): int
|
||||||
|
{
|
||||||
|
return Meta::select('value')->where(['key' => 'messages_received'])->first()->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,8 +38,8 @@ class DashPanelProvider extends PanelProvider
|
|||||||
])
|
])
|
||||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
||||||
->widgets([
|
->widgets([
|
||||||
Widgets\AccountWidget::class,
|
//Widgets\AccountWidget::class,
|
||||||
Widgets\FilamentInfoWidget::class,
|
//Widgets\FilamentInfoWidget::class,
|
||||||
])
|
])
|
||||||
->middleware([
|
->middleware([
|
||||||
EncryptCookies::class,
|
EncryptCookies::class,
|
||||||
|
|||||||
@@ -54,7 +54,3 @@ if ($messages) {
|
|||||||
|
|
||||||
// Close mailbox connection
|
// Close mailbox connection
|
||||||
imap_close($inbox);
|
imap_close($inbox);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -55,6 +55,3 @@ if ($messages) {
|
|||||||
// Close mailbox connection
|
// Close mailbox connection
|
||||||
imap_close($inbox);
|
imap_close($inbox);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user