CurrentUser ​
Class: Unusualify\Modularous\Http\ViewComposers\CurrentUser
Source: src/Http/ViewComposers/CurrentUser.php
Injects the authenticated user into every view as $currentUser. Uses Modularous configured auth guard rather than the default Laravel guard, ensuring the correct user is resolved in multi-guard setups.
Injected Variable ​
| Variable | Type | Description |
|---|---|---|
currentUser | array|null | The authenticated user's profile data, or null when no user is authenticated |
Behaviour ​
- Resolves the auth guard name from
Modularous::getAuthGuardName(). - Retrieves the authenticated user via
AuthFactory::guard($guardName)->user(). - If a user is found, passes it through the
get_user_profile($user)helper, which normalises the model into a plain array with the fields expected by the frontend (name, email, avatar, role, etc.). - Exposes the result as
compact('currentUser')—nullwhen unauthenticated.
Usage in Views ​
blade
{{-- Blade --}}
@if($currentUser)
Welcome, {{ $currentUser['name'] }}
@endifjs
// Inertia (shared props)
const { currentUser } = usePage().propsConfiguration ​
The guard name is read from the Modularous config:
php
// config/modularous.php
'auth' => [
'guard' => 'web', // used by Modularous::getAuthGuardName()
],