Setup Laravel API

First, set up the Laravel API as you normally would. Here we are using Laravel Sail. If you choose to run Laravel via Sail, your API will be accessible via http://localhost.

Make sure you change the following in your .env file:


To this:


Add a sender address in the .env so that email can be sent.

Running Artisan Commands

You need to use the sail command to enable artisan to run within the Docker container.

Example of running a migration:

sail up -d
sail artisan migrate

Install Sanctum

The full documentation can be found on the Laravel website.

composer require laravel/sanctum

sail artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

Sanctum needs some specific set up to enable it to work with a separate SPA. First lets add the following in your .env file:


The stateful domain tells Sanctum which domain you are using for the SPA. You can find the full notes and config for this in the config/sanctum.php file. As we are using cookies and sessions for authentication you need to add a session domain. This determines which domain the cookie is available to in your application. Full notes can be found in the config/session.php file and the official documentation.

Add Sanctum's middleware to your api middleware group within your application's app/Http/Kernel.php file:

'api' => [

Install Fortify

The full documentation can be found on the Laravel website.

composer require laravel/fortify

sail artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"

Ensure the FortifyServiceProvider class is registered within the providers array of your application's config/app.php file.

 * Application Service Providers...


Database Seeding

Set up a seed for adding a test user, in the DatabaseSeeder.php file add the following:

        'name' => 'Luke Skywalker',
        'email' => '',
        'email_verified_at' => null,

Run the migrations:

sail artisan migrate --seed