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();
|
2023-01-05 17:01:42 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
return view('notifications.index')->with([
|
2023-01-05 17:01:42 +00:00
|
|
|
'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();
|
2023-01-05 17:01:42 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
return view('notifications.show')->with([
|
2023-01-05 17:01:42 +00:00
|
|
|
'notification' => $notification,
|
2021-06-05 09:26:32 +00:00
|
|
|
]);
|
|
|
|
}
|
2022-06-02 06:44:54 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
public function readAll()
|
|
|
|
{
|
2022-06-02 06:44:54 +00:00
|
|
|
$notifications = Auth::user()->notifications()->get();
|
2023-01-05 17:01:42 +00:00
|
|
|
foreach ($notifications as $notification) {
|
2022-06-02 06:44:54 +00:00
|
|
|
$notification->markAsRead();
|
|
|
|
}
|
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return redirect()->back();
|
2022-06-02 06:44:54 +00:00
|
|
|
}
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|