Skip to content

Laravel doctrine integration for the official laravel-sanctum package

License

Notifications You must be signed in to change notification settings

bolivir/laravel-doctrine-sanctum

Repository files navigation

Laravel Doctrine Sanctum

example branch parameter

The original Laravel Sanctum works via eloquent, this package makes it work with laravel-doctrine/orm package (https://github.com/laravel-doctrine/orm)

Versions

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

Installation

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"

Configuration / Setup

Creating the Access Token Model

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;
        
      .......
      .......
}

Updating the UserModel

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.

Creating the database table

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 with migrations:migrate

Ready to use

Implement your login logic and start creating access tokens on succesfull login.

class MyLoginService
{       
      .......
      .......
      public function login() 
      {
        ....
        ....
        $accessToken = $this->tokenRepository->createToken($user, 'tokenName');
      }
}

See the WIKI for more detailed steps.

https://github.com/bolivir/laravel-doctrine-sanctum/wiki

About

Laravel doctrine integration for the official laravel-sanctum package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages