The original Laravel Sanctum works via eloquent, this package makes it work with laravel-doctrine/orm package (https://github.com/laravel-doctrine/orm)
Version | Supported Sanctum Version | Supported Laravel-Doctrine ORM Version |
---|---|---|
~1.0 | ^2.0 | ^1.0 |
~2.0 | ^2.0 | ^2.0 |
~3.0 | ^3.0 | ^2.0 |
~4.0 | ^4.0 | ^2.0 |
~5.0 | ^4.0 | ^3.0 |
Start by installing the package with the following command:
composer require "bolivir/laravel-doctrine-sanctum"
To publish the config use:
php artisan vendor:publish --tag="config" --provider="Bolivir\LaravelDoctrineSanctum\LaravelDoctrineSanctumProvider"
Start by creating your accessTokenModel, and implement the interface
IAccessToken
.
class AccessToken implements IAccessToken
{
use TAccessToken;
}
You can use the Trait TAccessToken
or just implement the interface by your self.
class AccessToken implements IAccessToken
{
protected string $id;
protected string $name;
protected string $token;
.......
.......
}
Your user model should implement the interface ISanctumUser
.
You dont need to implement the Authenticable
on your user model directly, it is required inside the ISanctumUser
Now you can choose to use the trait TAccessToken
or implement the interface yourself.
Laravel sanctum uses the database to store the access tokens. There are multiple options available to generate the database table sql
- If you are using laravel migrations, run
migrations:diff
after the creation of your model and metadata (xml). Then execute the migration withmigrations:migrate
Implement your login logic and start creating access tokens on succesfull login.
class MyLoginService
{
.......
.......
public function login()
{
....
....
$accessToken = $this->tokenRepository->createToken($user, 'tokenName');
}
}
https://github.com/bolivir/laravel-doctrine-sanctum/wiki