0
votes

I have database table name admins, and i want to create login session for these tabel, i try to create login function with middleware session guard but i got an notification error below:

Method Illuminate\Auth\SessionGuard::admin does not exist. (View: C:\xampp\htdocs\weddinc\weddinc7\weddinc\resources\views\layouts\admin_layout.blade.php)

Can anyone help me to solve this problem? Note: i'm use Laravel 6.2 Framework PHP

Here is my Controllers:

...
    public function login(Request $request)
    {
        if (Auth::guard('owner')->attempt(['email' => $request->email, 'password' => $request->password ])) {
            return redirect()->intended(route('index.owner'));
        }
        return back()->withInput($request->only('email', 'remember'));
    }
...
}

Here is my View:

...
      <div class="d-sm-none d-lg-inline-block">{{ auth()->admin()->name }}</div></a>
...

And Here is my Guard config/auth:

<?php

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

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

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
            'hash' => false,
        ],
        'owner' => [
            'driver' => 'session',
            'provider' => 'owners',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        'owners' => [
            'driver' => 'eloquent',
            'model' => App\Owner::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],
    ],

    'passwords' => [
...
        'admins' => [
            'provider' => 'admins',
            'table' => 'password_reset',
            'expire' => 60,
        ],
    ],

];

Can anyone help me? Thankyou

2
where did you see Auth::admin() or auth()->admin()? what reference are you using? - lagbox

2 Answers

1
votes

Try accessing like this in view

<div class="d-sm-none d-lg-inline-block">{{ \Auth::guard('admin')->user()->name }}</div></a>
0
votes

You need to use user instead of users, user is provided with Auth and will get the current logged in user id.

$id = \Auth::user()->id;

Or you want to get the user

$user = \Auth::user();