PHPackages                             matbcvo/laravel-token-auth - 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. matbcvo/laravel-token-auth

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

matbcvo/laravel-token-auth
==========================

1.0.2(1y ago)04MITPHPPHP ^8.0

Since Dec 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/matbcvo/laravel-token-auth)[ Packagist](https://packagist.org/packages/matbcvo/laravel-token-auth)[ RSS](/packages/matbcvo-laravel-token-auth/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Token Auth
==================

[](#laravel-token-auth)

A lightweight package that simplifies API token management in your Laravel applications. It provides Artisan commands and middleware support to create, manage, and authenticate API tokens efficiently.

Features
--------

[](#features)

- Create API tokens: Generate and store new API tokens.
- List API tokens: View existing tokens with their details.
- Delete API tokens: Remove existing tokens with confirmation prompts.
- Middleware integration: Secure your API routes with a simple token-based authentication middleware.

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

[](#installation)

Install the package via Composer:

```
composer require matbcvo/laravel-token-auth
```

Publish the migration files to your application's `database/migrations` directory:

```
php artisan vendor:publish --provider="Matbcvo\LaravelTokenAuth\LaravelTokenAuthServiceProvider" --tag=migrations
```

Run the migrations to create the `api_tokens` table in your database:

```
php artisan migrate
```

Middleware
----------

[](#middleware)

To secure your routes using the provided middleware, you can authenticate API requests based on a token.

### Apply middleware to API routes

[](#apply-middleware-to-api-routes)

The package registers a middleware alias `auth.token`. You can use this alias:

```
use Illuminate\Support\Facades\Route;

Route::middleware('auth.token')->group(function () {
    Route::get('/protected-route', function () {
        return response()->json(['message' => 'You have access to this route!']);
    });
});
```

You can use the middleware class directly for explicit clarity:

```
use Illuminate\Support\Facades\Route;
use Matbcvo\LaravelTokenAuth\Http\Middleware\AuthenticateApiToken;

Route::middleware(AuthenticateApiToken::class)->group(function() {
    Route::get('/protected-route', function () {
        return response()->json(['message' => 'You have access to this route!']);
    });
});
```

Commands
--------

[](#commands)

This package provides the following Artisan commands:

### Create a new API token

[](#create-a-new-api-token)

To generate and save a new API token, use the following command:

```
php artisan api-token:create {name} {--expires=}
```

Parameters:

- `name` (required): This is the descriptive name for the token, useful for identifying its purpose.
- `--expires` (optional): The token's expiration time in minutes. If not provided, the token will not expire.

### List all API tokens

[](#list-all-api-tokens)

View all existing API tokens:

```
php artisan api-token:list
```

### Delete an API token

[](#delete-an-api-token)

Delete a specific API token by its ID:

```
php artisan api-token:delete {id}
```

You’ll be asked to confirm before deletion.

Configuration
-------------

[](#configuration)

The package provides a configuration file to customize its behavior. To publish the configuration file, run:

```
php artisan vendor:publish --provider="Matbcvo\LaravelTokenAuth\LaravelTokenAuthServiceProvider" --tag=config
```

### Available configuration options

[](#available-configuration-options)

The configuration file includes the following options:

- Token length

    Defines the length of the API token. By default, it is set to 60 characters.

    ```
    'token_length' => 60,
    ```

Contribution
------------

[](#contribution)

Contributions are welcome! If you encounter issues or have feature requests, please submit them via GitHub issues.

License
-------

[](#license)

This package is open-source and available under the MIT License.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance41

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

496d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0457c69d8e6da50d3f67462e97797c9f4f1196c66840b3377b3b9ff41c8c44b3?d=identicon)[matbcvo](/maintainers/matbcvo)

---

Top Contributors

[![matbcvo](https://avatars.githubusercontent.com/u/1006437?v=4)](https://github.com/matbcvo "matbcvo (15 commits)")

---

Tags

laravellaravel-apilaravel-api-authlaravel-api-authentication

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/matbcvo-laravel-token-auth/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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