Putra Fajar Hasanuddin
Putra Fajar Hasanuddin

Reputation: 1193

Get custom guard logged name in blade

i'm using custom guard

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'user' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

i want to get admin name on blade so i call it using

{{ Auth::guard('admin')->name }}

but i got error

Cannot access protected property Illuminate\Auth\SessionGuard::$name

how can i achieve this on laravel 5.3

Upvotes: 4

Views: 3638

Answers (1)

Tomas Buteler
Tomas Buteler

Reputation: 4117

Are you trying to get the name of the SessionGuard object or the name of the user that is signed in using the admin guard?

This might be what you are looking for:

Auth::guard('admin')->user()->name;

Just note that the above will only work if the user is logged in, as the user method will return null when they're not logged in. Here's how you'd check if they are logged in:

Auth::guard('admin')->check();

Upvotes: 8

Related Questions