PHPackages                             raid/guardian - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. raid/guardian

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

raid/guardian
=============

Raid Authentication Package

v1.2(1y ago)019MITPHPPHP ^8.2

Since Apr 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/0xKhdr/guardian)[ Packagist](https://packagist.org/packages/raid/guardian)[ RSS](/packages/raid-guardian/feed)WikiDiscussions 1.2 Synced 1mo ago

READMEChangelog (1)DependenciesVersions (6)Used By (0)

**Laravel Authentication Package**
==================================

[](#laravel-authentication-package)

This package provides a unified authentication flow by acting as a wrapper around any authentication package. It introduces several new concepts:

- [Authenticatable](#authenticatable)
- [Guardians](#guardian)
- [Authenticators](#authenticator)
- [Matchers](#matcher)
- [Norms](#norm)
- [Sequences](#sequence)
- [Drivers](#driver)

---

**Requirements**
----------------

[](#requirements)

- PHP `>= 8.2`
- An installed authentication package (e.g., Laravel Sanctum, Laravel Passport, or any other compatible package)

This package acts as a wrapper and requires an existing authentication package to provide the underlying authentication mechanisms.

---

**Installation**
----------------

[](#installation)

Install the package via Composer:

```
composer require raid/guardian
```

---

**Configuration**
-----------------

[](#configuration)

Publish the configuration file with the following command:

```
php artisan vendor:publish --provider="Raid\Guardian\Providers\GuardianServiceProvider"
```

---

**Usage**
---------

[](#usage)

Here is an example of using the package in a controller:

```
class LoginController extends Controller
{
    public function __invoke(Request $request, UserGuardian $guardian)
    {
        $authenticator = $guardian->attempt($request->only([
            'email', 'password',
        ]));

        return response()->json([
            'authenticator' => $authenticator->getName(),
            'token' => $authenticator->getToken(),
            'resource' => $authenticator->getAuthenticatable()->toArray(),
            'errors' => $authenticator->errors()->toArray(),
        ]);
    }
}
```

### **Key Components:**

[](#key-components)

- The `Guardian` manages the authentication process and returns an `Authenticator` instance.
- The `Authenticator` relies on `Matchers`, runs `Norms`, and executes `Sequences` for successful authentication.

---

**Core Components**
-------------------

[](#core-components)

### **Authenticatable**

[](#authenticatable)

The `Authenticatable` class is responsible for locating a user and returning an `Illuminate\Contracts\Auth\Authenticatable` instance.

#### **Example Implementation:**

[](#example-implementation)

```
