承接 setiawanhu/sanctum-auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

setiawanhu/sanctum-auth

最新稳定版本:2.0.0

Composer 安装命令:

composer require setiawanhu/sanctum-auth

包简介

Laravel package for generating user authentication feature using Laravel Sanctum

README 文档

README

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

统计信息

  • 总下载量: 2.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-19