Files
ladill-qr-plus/app/Http/Middleware/SetActingAccount.php
T
isaaccladandCursor 8c3e9d3c26
Deploy Ladill QR Plus / deploy (push) Successful in 42s
Add team, developers, PDF type, and QR rendering dependency.
Enables account collaboration, API tokens, hosted PDF codes, and fixes QR detail 500s by declaring chillerlan/php-qrcode.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 06:16:13 +00:00

33 lines
938 B
PHP

<?php
namespace App\Http\Middleware;
use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Symfony\Component\HttpFoundation\Response;
class SetActingAccount
{
public function handle(Request $request, Closure $next): Response
{
if ($user = $request->user()) {
$accountId = (int) $request->session()->get('ladill_account', $user->id);
if (! $user->canAccessAccount($accountId)) {
$accountId = $user->id;
$request->session()->put('ladill_account', $accountId);
}
$account = $accountId === $user->id ? $user : (User::find($accountId) ?? $user);
$request->attributes->set('actingAccount', $account);
View::share('actingAccount', $account);
View::share('accessibleAccounts', $user->accessibleAccounts());
}
return $next($request);
}
}