From c97b1fa1863a859907b42fa970480a9cf924ed50 Mon Sep 17 00:00:00 2001 From: 1Day Date: Thu, 2 Jun 2022 08:44:54 +0200 Subject: [PATCH] Added Readall Button --- app/Http/Controllers/NotificationController.php | 15 +++++++++------ resources/views/notifications/index.blade.php | 4 ++++ routes/web.php | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index c48ea1de..b8884e7e 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -2,11 +2,6 @@ namespace App\Http\Controllers; -use Illuminate\Contracts\View\Factory; -use Illuminate\Contracts\View\View; -use Illuminate\Http\Request; -use Illuminate\Http\Response; -use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Auth; class NotificationController extends Controller @@ -15,7 +10,6 @@ class NotificationController extends Controller public function index() { $notifications = Auth::user()->notifications()->paginate(); - return view('notifications.index')->with([ 'notifications' => $notifications ]); @@ -31,4 +25,13 @@ class NotificationController extends Controller 'notification' => $notification ]); } + + public function readAll(){ + $notifications = Auth::user()->notifications()->get(); + foreach($notifications as $notification){ + $notification->markAsRead(); + } + return $this->index(); + + } } diff --git a/resources/views/notifications/index.blade.php b/resources/views/notifications/index.blade.php index d240646b..91ddddd8 100644 --- a/resources/views/notifications/index.blade.php +++ b/resources/views/notifications/index.blade.php @@ -29,6 +29,10 @@

{{__('All notifications')}}

+ + + + @foreach($notifications as $notification)
diff --git a/routes/web.php b/routes/web.php index e9555c66..168549f7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,6 +58,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { })->middleware(['auth', 'throttle:3,1'])->name('verification.send'); #normal routes + Route::get('notifications/readAll',[NotificationController::class,'readAll'])->name('notifications.readAll'); Route::resource('notifications', NotificationController::class); Route::resource('servers', ServerController::class); Route::resource('profile', ProfileController::class);