43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\rangking;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('pages.dashboard');
|
|
}
|
|
public function index2(Request $request)
|
|
{
|
|
$selectedYear = $request->input('year');
|
|
$rankingsByYear = $this->getRankingsByYear($selectedYear);
|
|
|
|
// Fetch all years for the dropdown
|
|
$years = rangking::selectRaw('YEAR(created_at) as year')
|
|
->distinct()
|
|
->pluck('year');
|
|
|
|
return view('pages.dashboard', compact('rankingsByYear', 'years', 'selectedYear'));
|
|
}
|
|
|
|
private function getRankingsByYear($year = null)
|
|
{
|
|
if ($year) {
|
|
return rangking::whereYear('created_at', $year)
|
|
->selectRaw('YEAR(created_at) as year, COUNT(*) as count')
|
|
->groupBy('year')
|
|
->get()
|
|
->pluck('count', 'year');
|
|
} else {
|
|
return rangking::selectRaw('YEAR(created_at) as year, COUNT(*) as count')
|
|
->groupBy('year')
|
|
->get()
|
|
->pluck('count', 'year');
|
|
}
|
|
}
|
|
}
|