Files
mareike/app/Support/helpers.php
T
2026-09-04 09:27:48 +02:00

37 lines
912 B
PHP

<?php
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Auth;
if (!function_exists('currentUser')) {
/**
* Der aktuell eingeloggte Nutzer, oder null wenn niemand eingeloggt ist.
*/
function currentUser() : ?User {
return Auth::user();
}
}
if (!function_exists('currentUserOrFail')) {
/**
* Der aktuell eingeloggte Nutzer. Für Code hinter der auth-Middleware,
* wo ein fehlender Nutzer ein Programmierfehler ist.
*
* @throws AuthenticationException
*/
function currentUserOrFail() : User {
return Auth::user() ?? throw new AuthenticationException();
}
}
if (!function_exists('currentTenant')) {
/**
* Der über IdentifyTenant aufgelöste Tenant der aktuellen Anfrage.
*/
function currentTenant() : Tenant {
return app('tenant');
}
}