Browse Source

Added Readall Button

1Day 3 years ago
parent
commit
c97b1fa186

+ 9 - 6
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();
+
+    }
 }

+ 4 - 0
resources/views/notifications/index.blade.php

@@ -29,6 +29,10 @@
                 <div class="col-md-8">
                     <p>{{__('All notifications')}}</p>
                 </div>
+                    <a class="float-right">
+                        <a href="{{route('notifications.readAll')}}"><button class="btn btn-info btn-xs">{{__('mark all as read')}}</button></a>
+
+
                 @foreach($notifications as $notification)
                     <div class="col-md-8">
                         <div class="card">

+ 1 - 0
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);