PHPackages                             consilience/laravel-api-token-generator - 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. consilience/laravel-api-token-generator

ActiveLibrary[API Development](/categories/api)

consilience/laravel-api-token-generator
=======================================

Artisan command to generate API tokens for laravel applications

1.1.1(6y ago)1581[1 issues](https://github.com/consilience/laravel-api-token-generator/issues)MITPHP

Since Jul 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/consilience/laravel-api-token-generator)[ Packagist](https://packagist.org/packages/consilience/laravel-api-token-generator)[ RSS](/packages/consilience-laravel-api-token-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

laravel-api-token-generator
===========================

[](#laravel-api-token-generator)

Laravel supports API token authentication out of the box. When developing, and for internal (machine-to-machine) APIs, it is useful to be able to generate tokens for a user. This package provides a simple Artisan command to generate a token.

The token will be hashed using the `sha256` algorithm.

This package does not provide a database migration for the `api_token` column. That is left to your application.

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

[](#installation)

### Installing with composer:

[](#installing-with-composer)

`composer require consilience/laravel-api-token-generator`

### Lumen

[](#lumen)

For Laravel, the service provider and configuration file are registered automatically. With Lumen, additional entried are needed in `bootstrap/app.php`.

The service provider is registered:

```
$app->register(Consilience\Laravel\ApiTokenGenerator\Providers\ServiceProvider::class);

```

If the configuration file is published, add:

```
$app->configure('apitokens');

```

then copy `apitokens.php`:

```
cp vender/consilience/laravel-api-token-generator/apitokens.php config/apitokens.php

```

### Publishing assets:

[](#publishing-assets)

`php artisan vendor:publish --provider="Consilience\ApiTokenGenerator\ApiTokenGeneratorServiceProvider"`

### Configuration

[](#configuration)

You can change the model that will hold the API tokens. By default this will be `App\User`, but yu may want `App\Models\User` for example.

```
'model' => App\Models\User::class,

```

The `name_field` is an alternative column to `id` that can be used to uniquely identify a model instance:

```
'name_field' => 'name'

```

The token column will be `api_token` by default, but can be changed:

```
'token_field' => 'my_api_token_column',

```

Note: this package does not add the API token column to your users table. That is a step for other packages or your application deployment.

### Usage

[](#usage)

Generate a new token or replace the existing token for a user:

```
php artisan apitoken:generate --id=123 --generate
php artisan apitoken:generate --id=5fd40c23-fcda-4bdc-a07c-f2bfeb56bb03 --generate

```

The `id` is normally an integer, but some this should also work if the `id` is a string such as *UUID*.

A generated token will only be displayed once. It is encrypted for saving against the model, so cannot be recovered if not recorded immediately.

Where users are uniquely identified by another column, then that column can be used to identify the model instance to update with a new token:

```
php artisan apitoken:generate --name=bloggs@example.com --generate

```

Rather than generating a random token, you can set your own explicit tokanes. Use the `--token=` option to do this instead of the `--generate` option.

```
php artisan apitoken:generate --id=123 --token=d8a928b2043db77e340b523547bf16cb4aa483f0645fe0a290ed1f20aab76257

```

If using for automated deployment, you may want to use the `--no-ansi` option to remove control characters.

The `--check` option will tell you whether an instance has a token set or not:

```
$ php artisan apitoken:generate --id=11 --check
App\Models\User::11 has no API token set
No explicit token supplied (--token=) and no token to be generated (--generate)
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 63.2% 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 ~73 days

Total

3

Last Release

2355d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/395934?v=4)[Jason Judge](/maintainers/judgej)[@judgej](https://github.com/judgej)

---

Top Contributors

[![judgej](https://avatars.githubusercontent.com/u/395934?v=4)](https://github.com/judgej "judgej (12 commits)")[![Michael-Stokoe](https://avatars.githubusercontent.com/u/2981213?v=4)](https://github.com/Michael-Stokoe "Michael-Stokoe (7 commits)")

---

Tags

apiapi-tokenlaravellaravel-apilumenlumen-api

### Embed Badge

![Health badge](/badges/consilience-laravel-api-token-generator/health.svg)

```
[![Health](https://phpackages.com/badges/consilience-laravel-api-token-generator/health.svg)](https://phpackages.com/packages/consilience-laravel-api-token-generator)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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