PHPackages                             lukeraymonddowning/nightguard - 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. lukeraymonddowning/nightguard

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

lukeraymonddowning/nightguard
=============================

Set up Laravel Eloquent guards in seconds

0.2.0(5y ago)1134[1 PRs](https://github.com/lukeraymonddowning/nightguard/pulls)MITPHPPHP ^7.4|^8.0

Since Mar 12Pushed 5y ago2 watchersCompare

[ Source](https://github.com/lukeraymonddowning/nightguard)[ Packagist](https://packagist.org/packages/lukeraymonddowning/nightguard)[ RSS](/packages/lukeraymonddowning-nightguard/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

Nightguard
==========

[](#nightguard)

Set up Auth guards using Eloquent in seconds.

[![Unit Tests](https://github.com/lukeraymonddowning/nightguard/actions/workflows/main.yml/badge.svg)](https://github.com/lukeraymonddowning/nightguard/actions/workflows/main.yml)

Introduction
------------

[](#introduction)

Laravel guards provide a super convenient way of authorizing different areas of your application based on the *type* of your user. For a lot of projects, gates and permissions suffice, but guards go one step further by allowing you to use dedicated eloquent models for each area of authentication.

However, guards can be a little confusing to set up, especially if you're new to it all. The documentation is thorough, but because of the low level nature of guards, it can be overwhelming.

That's why Nightguard was created. Rather than you having to dig into config files and jump from file to file, you can have a guard set up around your own custom Eloquent model with **a single line of code**!

Installation
------------

[](#installation)

You can install Nightguard via composer:

```
composer require lukeraymonddowning/nightguard
```

Usage
-----

[](#usage)

Imagine we want an admin panel for our application. We want to have a dedicated `administrators` table, and an `Administrator` Eloquent model. Only administrators should be allowed into the admin panel. Even if a `User` model is logged in under the default guard, they should not have access to any admin route.

Let's start by creating a model and migration for our administrators. Nightguard provides a super convenient Artisan command that will create a model and migration with all the columns you'll need for authentication:

```
php artisan nightguard:model Administrator
```

That was simple!

With that out of the way, all that's left is to set up the guard. Head in to your `AuthServiceProvider`, and add the following code to your `boot` method:

```
public function boot()
{
    Nightguard::create(App\Models\Administrator::class);
}
```

...and voilà! You've successfully registered a gate that only an authenticated `Administrator` can access.

If you create a route protected by your new 'administrator' gate, it will be protected:

```
Route::get('example-url', fn() => 'Super secret!')->middleware('auth:administrator');
```

> The name of the guard is set automatically based on the class name of the model you pass to the `create` method. The guard name will always be singular and kebab-cased.

Nightguard Facade
-----------------

[](#nightguard-facade)

The `Nightguard` Facade includes the following methods:

### `create($model, $guard = null)`

[](#createmodel-guard--null)

This is how you register a new Eloquent guard. The first parameter should be the class name of your eloquent model (eg: `App\Models\Administrator::class`).

The second parameter is entirely optional and is only needed if you want to use a custom guard name. When omitted, Nightguard will guess the guard name based on your model name.

You should place these method calls in the `boot` method of one of your Service Providers.

Commands
--------

[](#commands)

Nightguard provides the following Artisan commands for you to use:

### `php artisan nightguard:model YourModelName`

[](#php-artisan-nightguardmodel-yourmodelname)

This command allows you to quickly scaffold files for your new Authenticatable Eloquent model. The database will have all the required columns, and the model will extend the correct classes and have the desired traits and casts out of the box.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1937d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/139db346fa173a79481af05b0455e2e8ad7d2ab594c7f53bde3522a3dfeeaf25?d=identicon)[96downlu](/maintainers/96downlu)

---

Top Contributors

[![lukeraymonddowning](https://avatars.githubusercontent.com/u/12202279?v=4)](https://github.com/lukeraymonddowning "lukeraymonddowning (23 commits)")

### Embed Badge

![Health badge](/badges/lukeraymonddowning-nightguard/health.svg)

```
[![Health](https://phpackages.com/badges/lukeraymonddowning-nightguard/health.svg)](https://phpackages.com/packages/lukeraymonddowning-nightguard)
```

###  Alternatives

[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[althinect/filament-spatie-roles-permissions

3481.1M10](/packages/althinect-filament-spatie-roles-permissions)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.0k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
