0

1)Laravel has a very good built in authentication system/module.I had read its documentation the confusion to me is what is definition of a driver in guard and provider?

2)Is defining a new guard means defining a new driver?

Ans Dev
  • 11
  • 4

1 Answers1

1

In the configuration defining a new Guard is defining a coupling of a driver and a provider. In the default setup the Guard web is the session driver and the users provider used together. The driver is the means of actually figuring out the user from a request and the provider is the interface to the records, in simplest terms.

At the class level a Guard is what the configuration refers to as a Driver.

namespace Illuminate\Auth;

class TokenGuard implements Guard

is the token driver in the api guard in the config.

namespace Illuminate\Auth;

class SessionGuard implement StatefulGuard, ...

is the session driver in the web guard.

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

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],
lagbox
  • 48,571
  • 8
  • 72
  • 83
  • But what if I want to use same driver but a different provider... Will it be same as defining a new *Gaurd* – Ans Dev Oct 25 '19 at 06:19
  • in the context of the `guards` array in the `config/auth.php` file, it would be a guard, in regards to the `auth` middleware and the `guard` method of the `AuthManager` that is what 'guard' means – lagbox Oct 25 '19 at 06:26