67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Models\Notification;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class AlertController extends Controller
|
||
|
|
{
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
$notifications = auth()->user()->notifications()
|
||
|
|
->orderBy('created_at', 'desc')
|
||
|
|
->paginate(20);
|
||
|
|
|
||
|
|
$unreadCount = auth()->user()->notifications()
|
||
|
|
->where('is_read', false)
|
||
|
|
->count();
|
||
|
|
|
||
|
|
$readCount = auth()->user()->notifications()
|
||
|
|
->where('is_read', true)
|
||
|
|
->count();
|
||
|
|
|
||
|
|
return view('alerts.index', compact('notifications', 'unreadCount', 'readCount'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function markAsRead(Notification $notification)
|
||
|
|
{
|
||
|
|
$this->authorize('view', $notification);
|
||
|
|
|
||
|
|
$notification->update(['is_read' => true]);
|
||
|
|
|
||
|
|
return redirect()->route('alerts.index')
|
||
|
|
->with('success', 'Alert marked as read.');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function markAllAsRead()
|
||
|
|
{
|
||
|
|
auth()->user()->notifications()
|
||
|
|
->where('is_read', false)
|
||
|
|
->update(['is_read' => true]);
|
||
|
|
|
||
|
|
return redirect()->route('alerts.index')
|
||
|
|
->with('success', 'All alerts marked as read.');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function destroy(Notification $notification)
|
||
|
|
{
|
||
|
|
$this->authorize('view', $notification);
|
||
|
|
|
||
|
|
$notification->delete();
|
||
|
|
|
||
|
|
return redirect()->route('alerts.index')
|
||
|
|
->with('success', 'Alert deleted.');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function deleteRead()
|
||
|
|
{
|
||
|
|
auth()->user()->notifications()
|
||
|
|
->where('is_read', true)
|
||
|
|
->delete();
|
||
|
|
|
||
|
|
return redirect()->route('alerts.index')
|
||
|
|
->with('success', 'All read alerts deleted.');
|
||
|
|
}
|
||
|
|
}
|