ctrlpanel/app/Http/Controllers/NotificationController.php

41 lines
951 B
PHP
Raw Normal View History

2021-06-05 09:26:32 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
class NotificationController extends Controller
{
2021-06-06 18:17:52 +00:00
/** Display a listing of the resource. */
2021-06-06 21:26:36 +00:00
public function index()
2021-06-05 09:26:32 +00:00
{
$notifications = Auth::user()->notifications()->paginate();
2021-06-05 09:26:32 +00:00
return view('notifications.index')->with([
'notifications' => $notifications,
2021-06-05 09:26:32 +00:00
]);
}
2021-06-06 18:17:52 +00:00
/** Display the specified resource. */
2021-06-06 21:26:36 +00:00
public function show(string $id)
2021-06-05 09:26:32 +00:00
{
$notification = Auth::user()->notifications()->findOrFail($id);
$notification->markAsRead();
2021-06-05 09:26:32 +00:00
return view('notifications.show')->with([
'notification' => $notification,
2021-06-05 09:26:32 +00:00
]);
}
2022-06-02 06:44:54 +00:00
public function readAll()
{
2022-06-02 06:44:54 +00:00
$notifications = Auth::user()->notifications()->get();
foreach ($notifications as $notification) {
2022-06-02 06:44:54 +00:00
$notification->markAsRead();
}
return redirect()->back();
2022-06-02 06:44:54 +00:00
}
2021-06-05 09:26:32 +00:00
}