StocksNew/Modules/Admin/app/Http/Controllers/NotificationController.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2024-08-27 12:03:06 +00:00
<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['notifications'] = auth()->user()->notifications;
return view('notification.index', $data);
}
public function markAsRead(Request $request)
{
$filterData = $request->all();
try {
$notification = auth()->user()->notifications()->where('id', $filterData['id'])->first();
if ($notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark As Read');
} catch (\Throwable $th) {
return redirect()->back()->withError('Something Went Wrong!');
}
}
public function markAllAsRead(Request $request)
{
try {
foreach (auth()->user()->unreadNotifications as $notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark All As Read');
} catch (\Throwable $th) {
//throw $th;
return redirect()->back()->withError('Something Went Wrong!');
}
}
}