Link to the repository
[Only for premium members]
[Only for premium members]
Let's start preparing to have a mobile app along with our web page. Here's our action plan:
Let's get started!
Our first step is to install Laravel API scaffolding:
php artisan install:api
This will install Sanctum into our application and set up a few things:
api.php
routes filesanctum.php
configuration filepersonal_access_tokens
tableThe only thing we have to do is add a trait to our Users Model:
app/Models/User.php
use Laravel\Sanctum\HasApiTokens; // ... class User extends Authenticatable{ /** @use HasFactory<\Database\Factories\UserFactory> */ use HasFactory, Notifiable; use HasFactory, Notifiable, HasApiTokens; // ...}
Once this is done, we are ready to create our first API endpoints.
Let's start our API implementation by creating the first endpoints:
These endpoints will live in a single Controller for our use case: