PHPackages                             uzzal/apitoken - 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. uzzal/apitoken

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

uzzal/apitoken
==============

Token checker for API

v2.0.0(8y ago)11221MITPHPPHP &gt;=5.6.4

Since Jul 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mahabubulhasan/apitoken)[ Packagist](https://packagist.org/packages/uzzal/apitoken)[ RSS](/packages/uzzal-apitoken/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

apitoken
========

[](#apitoken)

API access token to be used in support with [uzzal/acl](github.com/mahabubulhasan/acl) library

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

[](#installation)

```
composer require uzzal/apitoken

```

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

[](#configuration)

If you are using laravel 5.5+ then this library supports auto discovery. To configure manually just edit the `config/app.php` and add service provider like below.

```
Uzzal\ApiToken\TokenServiceProvider::class
```

At the `app\Http\Kernel.php` add this middleware

```
'token.checker' => \Uzzal\ApiToken\TokenChecker::class
```

### Database Migration

[](#database-migration)

This library depends on a database table called `auth_tokens`, and it comes with a migration. So you need to run the migration to add that table with a `artisan` command like

```
artisan migrate
```

Route
-----

[](#route)

Suppose your want to create a api url for the `FaqController` like this `http://YOUR-HOST/api/v1/faq` then, in your `route/api.php` file add your routes like the below

```
Route::group(['middleware' => ['token.checker'], 'prefix'=>'v1']
    , function(){
    Route::resource('faq', 'FaqController', [
        'only' => ['index']
    ]);
});
```

Alternatively, Just in case if you don't have a dedicated `route/api.php` file in that case in your default route file add the route as below:

```
Route::group(['middleware' => ['token.checker']
    , 'prefix'=>'api/v1'
    , 'namespace'=> 'Api']
    , function(){
    Route::resource('faq', 'FaqController', [
        'only' => ['index']
    ]);
});
```

Now you are all set, but one thing is you need a `_token` to access the protected url. and you will get the `_token` once you are logged in. So we need a `AuthController` to login for the API. Here is a sample `AuthController` under the `Api` namespace in the `app/Http/Controllers` directory.

### Controller

[](#controller)

```
