Files
ppeasy_vg12/app/Http/Controllers/Web/Profile/SessionsController.php
T
2026-10-09 08:21:06 +02:00

41 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Web\Profile;
use App\Http\Controllers\Controller;
use App\Repositories\Session\SessionRepository;
use App\Support\SessionPayload;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response as InertiaResponse;
class SessionsController extends Controller
{
public function __construct(private readonly SessionRepository $sessions) {}
public function index(): InertiaResponse
{
$user = auth()->user();
return Inertia::render('users/Sessions', [
'adminView' => false,
'user' => [
'id' => $user->id,
'nameOrEmail' => $user->present()->nameOrEmail,
],
'sessions' => SessionPayload::collection(
$this->sessions->getUserSessions($user->id),
fn (string $sessionId) => route('profile.sessions.invalidate', $sessionId)
),
]);
}
public function destroy($session): RedirectResponse
{
$this->sessions->invalidateSession($session->id);
return redirect()->route('profile.sessions')
->withSuccess(__('Session invalidated successfully.'));
}
}