first commit
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
<?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!');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user