PHPackages                             nrml-co/laravel-api-keys - 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. [API Development](/categories/api)
4. /
5. nrml-co/laravel-api-keys

ActiveLibrary[API Development](/categories/api)

nrml-co/laravel-api-keys
========================

Easy API keys - Because laravel/passport is hard.

1.2.0(5y ago)55.4k↑16.7%4[1 issues](https://github.com/nrml-co/laravel-api-keys/issues)MITPHPPHP ^7.1CI failing

Since Oct 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nrml-co/laravel-api-keys)[ Packagist](https://packagist.org/packages/nrml-co/laravel-api-keys)[ Docs](https://github.com/nrml-co/laravel-api-keys)[ RSS](/packages/nrml-co-laravel-api-keys/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

Laravel Api Keys
================

[](#laravel-api-keys)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cccb78223932931ddc5e5089d805b4c0fea495bb9b87d5a95d4b4a0e74ef1f89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e726d6c2d636f2f6c61726176656c2d6170692d6b6579732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nrml-co/laravel-api-keys)[![Build Status](https://camo.githubusercontent.com/3ccfea7157d40c2e48d551f91cfbed4078c3b552912abd1be1860d153f46b5ae/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e726d6c2d636f2f6c61726176656c2d6170692d6b6579732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/nrml-co/laravel-api-keys)[![Total Downloads](https://camo.githubusercontent.com/8a1c56bc7bd59b812dd7079b31e125284f53f46189df4359ad1d23a12b3bf446/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e726d6c2d636f2f6c61726176656c2d6170692d6b6579732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nrml-co/laravel-api-keys)

This package offers a different type on API key system for Laravel. The other options are either too simple or too complex.

Laravel ships with a guard that will allow you to create an access\_token field in your user migration. This allows easy access to the api routes.

This package offers:

- multiple keys per user
- sandbox and production keys
- scopes

Laravel/Passport is a the full on oauth implementation. This is a little more simple.

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

[](#installation)

You can install the package via composer:

```
composer require nrml-co/laravel-api-keys
php artisan migrate
```

Laravel 5.8 and above will register the service provider automatically.

Usage - Creating Keys
---------------------

[](#usage---creating-keys)

First add the HasApiKeys trait to the User model that ships with Laravel.

```
use NrmlCo\LaravelApiKeys\HasApiKeys;

/**
 * Class User
 * @package App
 */
class User extends Authenticatable
{
    use Notifiable;
    use HasApiKeys;
```

Next create a User. Easiest to to this part in tinker.

```
$user = User::create([
        'name' => 'Ed Anisko',
        'email' => 'ed@nrml.co',
        'email_verified_at' => now(),
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        'remember_token' => Str::random(10)
        ]);
```

The user needs to be logged in. Programmatically it looks like this.

```
Auth::setUser($user);
```

Now the package will create ApiKeys for the authorized user.

```
LaravelApiKeys::create(); // default is SANDBOX
```

Copy the new api key.

Using the your API Keys
-----------------------

[](#using-the-your-api-keys)

Add the new entry to the guards section of config/auth.php

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

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

        "api_key" => [
            'driver' => 'api_key'
        ]

    ]
```

Use the 'auth:api\_key' middleware in api.php routes.

```
Route::middleware('auth:api_key')->get('/user', function (Request $request) {
    return $request->user();
});
```

Replace the x-api-key header with your own api-key and test. Use the header Accept: application/json.

```
$ curl -X GET \
  http://homestead.test/api/user \
  -H 'Accept: application/json' \
  -H 'x-api-key: al4PA8V5jSuq4oFJOxK6lS4CeZEkDFtayBObJTHJ'
```

The above curl command will return the user authorized by the ApiKey.

```
{
    "id": 1,
    "name": "Ed Anisko",
    "email": "ed@nrml.co",
    "created_at": "2019-10-17 07:18:59",
    "updated_at": "2019-10-17 07:18:59"
}
```

### Testing

[](#testing)

```
phpunit
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

.

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ed Anisko](https://github.com/nrml-co)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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 ~47 days

Recently: every ~82 days

Total

8

Last Release

2118d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9271b3cfd68010a197c344c65ec6de40ae6fd156b22371270ed5d1f9b3142e56?d=identicon)[edanisko](/maintainers/edanisko)

---

Top Contributors

[![edanisko](https://avatars.githubusercontent.com/u/947502?v=4)](https://github.com/edanisko "edanisko (19 commits)")

---

Tags

alternativeapiapikeysguardkeyslaravelpassportphpsimpleapilaravelkeysapi keysnormalnrml-colaravel-api-keys

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nrml-co-laravel-api-keys/health.svg)

```
[![Health](https://phpackages.com/badges/nrml-co-laravel-api-keys/health.svg)](https://phpackages.com/packages/nrml-co-laravel-api-keys)
```

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k11.8M117](/packages/nuwave-lighthouse)[essa/api-tool-kit

set of tools to build an api with laravel

53390.1k](/packages/essa-api-tool-kit)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6804.7k6](/packages/hasinhayder-tyro)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[hasinhayder/tyro-login

Tyro Login - Beautiful, customizable authentication views for Laravel 12 &amp; 13

2464.9k6](/packages/hasinhayder-tyro-login)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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