diff --git a/app/Filament/Widgets/AbstractApplicationTablesChart.php b/app/Filament/Widgets/AbstractApplicationTablesChart.php index a8b1b75..8763ea1 100644 --- a/app/Filament/Widgets/AbstractApplicationTablesChart.php +++ b/app/Filament/Widgets/AbstractApplicationTablesChart.php @@ -17,7 +17,7 @@ protected function getType(): string return 'pie'; } - abstract protected function retrieveData(): \Illuminate\Support\Collection; + abstract protected function retrieveData(): array; protected function getData(): array { @@ -26,19 +26,18 @@ protected function getData(): array 'datasets' => [ [ 'label' => 'Total Tables', - 'data' => $data->pluck('count')->all(), + 'data' => array_values($data), 'backgroundColor' => [ - 'rgb(200, 180, 90)', + 'rgb(250, 80, 50)', 'rgb(0, 200, 255)', 'rgb(255, 200, 80)', 'rgb(250, 100, 200)', 'rgb(150, 100, 255)', 'rgb(0, 180, 0)', - 'rgb(250, 80, 50)', ], ], ], - 'labels' => $data->pluck('type')->all(), + 'labels' => array_keys($data), ]; } diff --git a/app/Filament/Widgets/ApplicationTablesAssignedChart.php b/app/Filament/Widgets/ApplicationTablesAssignedChart.php index fcba31e..c60c3c7 100644 --- a/app/Filament/Widgets/ApplicationTablesAssignedChart.php +++ b/app/Filament/Widgets/ApplicationTablesAssignedChart.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Models\Application; +use App\Models\TableType; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -10,8 +11,13 @@ class ApplicationTablesAssignedChart extends AbstractApplicationTablesChart { protected static ?string $heading = 'Total Tables Assigned (active)'; - protected function retrieveData(): \Illuminate\Support\Collection + protected function retrieveData(): array { - return Cache::remember('dd-admin-application-tables-assigned', 60, fn() => Application::query()->toBase()->join('table_types', 'table_type_assigned', '=', 'table_types.id')->select(DB::raw('COUNT(*) as count, name as type'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('name')->get()); + return Cache::remember('dd-admin-application-tables-assigned', 60, function(): array { + $tableTypeCount = Application::query()->toBase()->join('table_types', 'table_type_assigned', '=', 'table_types.id')->select(DB::raw('table_types.id as id, COUNT(*) as count'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('table_types.id')->get()->pluck('count', 'id'); + return TableType::all()->mapWithKeys(function(TableType $tableType) use ($tableTypeCount) { + return [ $tableType->name => $tableTypeCount[$tableType->id] ?? 0]; + })->toArray(); + }); } } diff --git a/app/Filament/Widgets/ApplicationTablesRequestedChart.php b/app/Filament/Widgets/ApplicationTablesRequestedChart.php index d91e62c..2444592 100644 --- a/app/Filament/Widgets/ApplicationTablesRequestedChart.php +++ b/app/Filament/Widgets/ApplicationTablesRequestedChart.php @@ -3,15 +3,22 @@ namespace App\Filament\Widgets; use App\Models\Application; +use App\Models\TableType; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class ApplicationTablesRequestedChart extends AbstractApplicationTablesChart { protected static ?string $heading = 'Total Tables Requested (active)'; - protected function retrieveData(): \Illuminate\Support\Collection + protected function retrieveData(): array { - return Cache::remember('dd-admin-application-tables-requested', 60, fn() => Application::query()->toBase()->join('table_types', 'table_type_requested', '=', 'table_types.id')->select(DB::raw('COUNT(*) as count, name as type'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('name')->get()); + return Cache::remember('dd-admin-application-tables-requested', 60, function(): array { + $tableTypeCount = Application::query()->toBase()->join('table_types', 'table_type_requested', '=', 'table_types.id')->select(DB::raw('table_types.id as id, COUNT(*) as count'))->where('type', '=', 'dealer')->whereNull('canceled_at')->whereNull('waiting_at')->groupBy('table_types.id')->get()->pluck('count', 'id'); + return TableType::all()->mapWithKeys(function(TableType $tableType) use ($tableTypeCount) { + return [ $tableType->name => $tableTypeCount[$tableType->id] ?? 0]; + })->toArray(); + }); } } diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 1d5757a..fa9336c 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -28,7 +28,7 @@ public function panel(Panel $panel): Panel ->id('admin') ->path('admin') ->userMenuItems([ - 'logout' => MenuItem::make()->label('Log out')->url(fn () => route('auth.frontchannel-logout')), + 'logout' => MenuItem::make()->label('Log out')->url(fn () => route('auth.frontchannel-logout-post')), ]) ->colors([ 'primary' => Color::Amber, diff --git a/routes/web.php b/routes/web.php index 400ea5b..2fd990a 100755 --- a/routes/web.php +++ b/routes/web.php @@ -26,7 +26,7 @@ }); Route::get('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout'); -Route::post('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout'); +Route::post('/auth/frontchannel-logout', \App\Http\Controllers\Auth\FrontChannelLogoutController::class)->name('auth.frontchannel-logout-post'); Route::get('/', function () { return \Illuminate\Support\Facades\Redirect::route('dashboard');