feat: complete approval workflow
This commit is contained in:
35
app/Http/Controllers/NotificationController.php
Normal file
35
app/Http/Controllers/NotificationController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user