Skip to content

Application API

If you feel like opting in for the Laracogs starter kit. You can also easily build in an API layer. Running the grafite:api command will set up the bare bones components, but you can also use the API tools as a part of the CRUD now by using the --api option.

composer require tymon/jwt-auth


php artisan grafite:api

Essentially you want to do all the basic setup for JWT such as everything in here: Then follow the directions regarding installation on:

Add this to the app/Providers/RouteServiceProvider.php file in the mapWebRoutes(Router $router) function:

require base_path('routes/api.php');

Add to the app/Http/Kernal.php under routeMiddleware:

'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,

Add to except attribute the app/Http/Middleware/VerifyCsrfToken.php (You also have to do this for CRUDs you add):


If you use Apache add this to the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Also update your jwt config file and set the user to:


What API publishes

The command will overwrite any existing files with the api version of them:

  • app/Http/Controllers/Api/AuthController.php
  • app/Http/Controllers/Api/UserController.php
  • routes/api.php