33 lines
892 B
PHP
33 lines
892 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function index(Request $request): View
|
|
{
|
|
return view('notifications.index', [
|
|
'notifications' => $request->user()->notifications()->latest()->paginate(30),
|
|
]);
|
|
}
|
|
|
|
public function markRead(Request $request, string $id): RedirectResponse
|
|
{
|
|
$notification = $request->user()->notifications()->whereKey($id)->firstOrFail();
|
|
$notification->markAsRead();
|
|
|
|
return back()->with('status', 'Notification marked read.');
|
|
}
|
|
|
|
public function markAllRead(Request $request): RedirectResponse
|
|
{
|
|
$request->user()->unreadNotifications->markAsRead();
|
|
|
|
return back()->with('status', 'Notifications marked read.');
|
|
}
|
|
}
|