add dashboard

This commit is contained in:
Muzakki Parsaoran Siregar 2025-10-15 10:26:48 +07:00
parent d2b2db90a6
commit ab8d7b4a3c
3 changed files with 69 additions and 24 deletions

View File

@ -2,14 +2,31 @@
namespace App\Http\Controllers;
use App\Models\Kategori;
use App\Models\Template;
use App\Models\Pelanggan;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index()
{
// Karena jumlah kategori, template, dan pelanggan statis,
// maka kita tidak perlu query database di sini.
return view('admin.dashboard');
// Hitung total data
$totalKategori = Kategori::count();
$totalTemplate = Template::count();
$totalPelanggan = Pelanggan::count();
// Ambil pelanggan terbaru (misal 5 terakhir)
$pelangganTerbaru = Pelanggan::with(['template.kategori'])
->latest()
->take(5)
->get();
return view('admin.dashboard', compact(
'totalKategori',
'totalTemplate',
'totalPelanggan',
'pelangganTerbaru'
));
}
}

View File

@ -21,27 +21,29 @@
class="bg-white rounded-lg shadow-md p-4 flex justify-between items-center hover:shadow-lg transition-transform duration-300 transform hover:-translate-y-2">
<div>
<h5 class="text-gray-500 text-sm">Kategori</h5>
<h3 class="font-bold text-xl">12</h3>
<h3 class="font-bold text-xl">{{ $totalKategori }}</h3>
</div>
<div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-lg flex items-center justify-center text-xl">
<i class="bi bi-diagram-3"></i>
</div>
</div>
<div
class="bg-white rounded-lg shadow-md p-4 flex justify-between items-center hover:shadow-lg transition-transform duration-300 transform hover:-translate-y-2">
<div>
<h5 class="text-gray-500 text-sm">Template</h5>
<h3 class="font-bold text-xl">34</h3>
<h3 class="font-bold text-xl">{{ $totalTemplate }}</h3>
</div>
<div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-lg flex items-center justify-center text-xl">
<i class="bi bi-card-list"></i>
</div>
</div>
<div
class="bg-white rounded-lg shadow-md p-4 flex justify-between items-center hover:shadow-lg transition-transform duration-300 transform hover:-translate-y-2">
<div>
<h5 class="text-gray-500 text-sm">Pelanggan</h5>
<h3 class="font-bold text-xl">56</h3>
<h3 class="font-bold text-xl">{{ $totalPelanggan }}</h3>
</div>
<div class="w-12 h-12 bg-blue-100 text-blue-600 rounded-lg flex items-center justify-center text-xl">
<i class="bi bi-person"></i>
@ -50,33 +52,53 @@
</div>
<!-- Recent Pelanggan -->
<div class="bg-white rounded-lg shadow-sm mt-6">
<div class="p-4 overflow-x-auto">
<div class="bg-white rounded-lg shadow mt-6 overflow-x-auto">
<div class="p-4">
<h4 class="text-lg font-bold mb-3">Pelanggan Terbaru</h4>
<table class="w-full text-left border-collapse border border-gray-300">
<table class="w-full border border-gray-200 text-left border-collapse">
<thead class="bg-gray-100">
<tr>
<th class="p-2 border border-gray-300 text-center w-16">Nomor</th>
<th class="p-2 border border-gray-300 text-center">Nama</th>
<th class="p-2 border border-gray-300 text-center">Template</th>
<th class="p-2 border border-gray-300 text-center">Kategori</th>
<th class="p-2 border border-gray-300 text-center">Email</th>
<th class="p-2 border border-gray-300 text-center">No. Telepon</th>
<th class="p-2 border border-gray-300 text-center">Harga</th>
<th class="p-2 border border-gray-300 text-center">Tanggal Pemesanan</th>
<th class="p-2 border border-gray-300 text-center">Aksi</th>
<th class="px-3 py-2 border border-gray-200 w-[50px] text-center">No.</th>
<th class="px-3 py-2 border border-gray-200 text-center">Nama</th>
<th class="px-3 py-2 border border-gray-200 text-center">Template</th>
<th class="px-3 py-2 border border-gray-200 text-center">Kategori</th>
<th class="px-3 py-2 border border-gray-200 text-center">Email</th>
<th class="px-3 py-2 border border-gray-200 text-center">No. Telepon</th>
<th class="px-3 py-2 border border-gray-200 text-center">Harga</th>
<th class="px-3 py-2 border border-gray-200 text-center">Tanggal Pemesanan</th>
</tr>
</thead>
<tbody>
@forelse ($pelangganTerbaru as $index => $p)
<tr class="hover:bg-gray-50">
<td class="px-3 py-2 border border-gray-200 text-center">{{ $index + 1 }}</td>
<td class="px-3 py-2 border border-gray-200 text-center">{{ $p->nama_pemesan }}</td>
<td class="px-3 py-2 border border-gray-200 text-center">
{{ $p->template->nama_template ?? '-' }}
</td>
<td class="px-3 py-2 border border-gray-200 text-center">
{{ $p->template->kategori->nama ?? '-' }}
</td>
<td class="px-3 py-2 border border-gray-200 text-center">{{ $p->email }}</td>
<td class="px-3 py-2 border border-gray-200 text-center">{{ $p->no_tlpn }}</td>
<td class="px-3 py-2 border border-gray-200 text-center">
Rp {{ number_format($p->harga, 0, ',', '.') }}
</td>
<td class="px-3 py-2 border border-gray-200 text-center">
{{ $p->created_at->translatedFormat('d M Y') }}
</td>
</tr>
@empty
<tr>
<td colspan="9" class="p-2 text-center text-gray-500 border border-gray-300">
<td colspan="8" class="px-3 py-4 text-center text-gray-500 border border-gray-200">
Belum ada data pelanggan.
</td>
</tr>
@endforelse
</tbody>
</table>
<!-- Pagination Dummy -->
<!-- Pagination Placeholder -->
<div class="p-4 flex justify-center">
<div class="flex space-x-1">
<span class="px-3 py-1 rounded-lg bg-gray-200 text-gray-500 cursor-not-allowed">Prev</span>

View File

@ -71,5 +71,11 @@ Route::prefix('admin')->name('admin.')->group(function () {
// REVIEW / ULASAN
// ----------------------------
Route::resource('reviews', ReviewController::class)->except(['create', 'edit', 'update', 'show', 'store']);
// Dashboard
Route::get('/admin/pelanggan/{id}', [PelangganController::class, 'show'])->name('pelanggan.show');
});
});