setiawanhu/sanctum-auth

Laravel package for generating user authentication feature using Laravel Sanctum
2,810 13
Install
composer require setiawanhu/sanctum-auth
Latest Version:2.0.0
PHP:^8.0.2
License:MIT
Last Updated:Nov 15, 2023
Links: GitHub  ·  Packagist
Maintainer: setiawanhu

Laravel sanctum-auth Package

Latest Stable Version Total Downloads License

Laravel package for generating user authentication feature using Laravel Sanctum

For information & usage about Laravel Sanctum, please refer to Laravel Sanctum documentation.

Get Started

Include the Sanctum Auth package by calling this composer command in project root:

composer require setiawanhu/sanctum-auth

Note: This package is only supporting Laravel 9

Usage

We may publish the Sanctum Auth migration files using vendor:publish artisan command:

php artisan vendor:publish --provider="Hu\Auth\SanctumAuthServiceProvider"

This command will copy the user role's migration file to /database/migrations folder and will publish the laravel/sanctum configuration and migration files.

Then, run Sanctum Auth artisan command by running:

php artisan sanctum-auth:controller [{type} --force]

This command will generate the auth routing out of the box.

Note:

  1. The type argument is optional with default value are token. The controller will be generated based on given argument value. Available types are token and spa.

  2. The --force option is optional. We may use it for ignoring existing controller.

Then, make User model to extend AuthModel class:

use Hu\Auth\AuthModel;

class User extends AuthModel {
    //...
}

Using Roles

if the User has roles, we may use the HasRole trait to the User model:

use Hu\Auth\HasRole;

class User extends AuthModel {

    use HasRole;
    
    //...
}

Then, we add a new field to the users table:

//...

Schema::create('users', function (Blueprint $table) {

    //...
    
    $table->unsignedBigInteger('role_id')
    
    //...
    
}

//...

Then, run the database migration command:

php artisan migrate

Dig Deeper

Please check wiki for more details about sanctum-auth usage

Related Packages

pictastudio/auth

Opinionated API authentication and authorization package for Laravel Sanctum wit...

48 0
d076/sanctum-refresh-tokens

Refresh token realization for laravel sanctum

5,984 6
laravel/sanctum

Laravel Sanctum provides a featherweight authentication system for SPAs and simp...

220,492,575 2,986
xaamin/sanctum

Laravel/Lumen Sanctum provides a featherweight authentication system for SPAs an...

3,197 1
coderstm/laravel-core

Laravel Core package that provides essential core functionalities and utilities...

2,299 0

Version History

Version Released PHP Laravel License
2.0.0 ^8.0.2 ^9.21 MIT
1.4.0 ^7.2|^8.0 ^7.0|^8.0 MIT
1.3.0 ^7.2.5 ^7.0|^8.0 MIT
1.2.0 ^7.2.5 ^7.0 MIT
1.1.1 ^7.2.5 ^7.0 MIT