git add .
git commit "fix dashboard charts rendering and views data display"
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\Admin;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Tour;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
@@ -21,28 +22,37 @@ class DashboardController extends Controller
|
||||
|
||||
$flightsCount = Flight::count();
|
||||
|
||||
$tourViews= Tour::query()
|
||||
->selectRaw('DATE(created_at) as date,SUM(views) as total')
|
||||
->where('created_at','>=',now()->subDays(9))
|
||||
->groupBy('date')
|
||||
->orderBy('date')
|
||||
->get();
|
||||
$tourViews = $this->getViewsForLast10Days(Tour::class, 'tour_views');
|
||||
|
||||
$flightViews=Flight::query()
|
||||
->selectRaw('DATE(created_at) as date,SUM(views) as total')
|
||||
->where('created_at','>=',now()->subDays(9))
|
||||
->groupBy('date')
|
||||
->orderBy('date')
|
||||
->get();
|
||||
$flightViews = $this->getViewsForLast10Days(Flight::class, 'flight_views');
|
||||
|
||||
$logs = ActivityLog::with('admin')
|
||||
->latest()
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
return view('admin.dashboard',compact('adminsCount',
|
||||
'usersCount','toursCount','flightsCount','tourViews',
|
||||
'flightViews','logs'
|
||||
return view('admin.dashboard', compact(
|
||||
'adminsCount',
|
||||
'usersCount', 'toursCount', 'flightsCount', 'tourViews',
|
||||
'flightViews', 'logs'
|
||||
));
|
||||
}
|
||||
|
||||
private function getViewsForLast10Days(string $model, string $cachePrefix)
|
||||
{
|
||||
$ids = $model::pluck('id');
|
||||
|
||||
return collect(range(9, 0))->map(function ($i) use ($ids, $cachePrefix) {
|
||||
$date = now()->subDays($i)->format('Y-m-d');
|
||||
|
||||
$total = $ids->sum(function ($id) use ($cachePrefix, $date) {
|
||||
return Cache::get("{$cachePrefix}:{$id}:{$date}", 0);
|
||||
});
|
||||
|
||||
return [
|
||||
'date' => verta($date)->format('m/d'),
|
||||
'total' => (int) $total,
|
||||
];
|
||||
})->values();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +87,6 @@ class TourController extends Controller
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function edit(Tour $tour)
|
||||
{
|
||||
return view('admin.tours.edit',compact('tour'));
|
||||
|
||||
Reference in New Issue
Block a user