academy/app/Http/Controllers/AdminDashboardController.php

43 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Timetable;
use App\Models\Notification;
class AdminDashboardController extends Controller
{
public function index()
{
if (!session()->has('admin_id')) {
return redirect()->route('admin.login')->with('error', 'Please login first.');
}
$totalTimetableSlots = Timetable::count();
$unreadNotifications = Notification::where('target_role', 'admin')
->where('is_read', false)
->count();
$notifications = Notification::where('target_role', 'admin')
->orderBy('created_at', 'desc')
->take(5)
->get();
return view('admin.admindashboard', compact(
'totalTimetableSlots',
'unreadNotifications',
'notifications'
));
}
public function markAsRead($id)
{
$notification = Notification::findOrFail($id);
$notification->update(['is_read' => true]);
return redirect()->back()->with('success', 'Notification marked as read!');
}
}