Added Readall Button

This commit is contained in:
1Day 2022-06-02 08:44:54 +02:00
parent 0f5369043d
commit c97b1fa186
3 changed files with 14 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -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">

View file

@ -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);