36 lines
993 B
PHP
36 lines
993 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function index(Request $request): Response
|
|
{
|
|
return Inertia::render('notifications/index', [
|
|
'notifications' => $request->user()->notifications()->latest()->paginate(20),
|
|
]);
|
|
}
|
|
|
|
public function read(Request $request, string $notification): RedirectResponse
|
|
{
|
|
$item = $request->user()->notifications()->whereKey($notification)->firstOrFail();
|
|
$item->markAsRead();
|
|
|
|
$url = is_string($item->data['url'] ?? null) ? $item->data['url'] : '/notificacoes';
|
|
|
|
return redirect()->to($url);
|
|
}
|
|
|
|
public function readAll(Request $request): RedirectResponse
|
|
{
|
|
$request->user()->unreadNotifications->markAsRead();
|
|
|
|
return back()->with('success', 'Notificações marcadas como lidas.');
|
|
}
|
|
}
|