arjunyuvanesh/common-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

arjunyuvanesh/common-auth

Composer 安装命令:

composer require arjunyuvanesh/common-auth

包简介

README 文档

README

A highly professional, dynamic, and reusable Laravel Authentication package built specifically to support Email, Mobile, or Username logins seamlessly, integrated deeply with spatie/laravel-permission.

Features

  • Dynamic Login: Users can log in using Email, Mobile, or Username via a single input field.
  • Configurable Registration: Dynamically define required registration fields across different projects without altering the package code.
  • Smart Database Migrations: Safely extends the default Laravel users table without destroying existing data.
  • Spatie Integration: Automatically assigns default roles upon registration.
  • Password Resets: Fully integrated with Laravel's native Password Broker.
  • Clean Architecture: Built following STRICT SOLID principles and thin controllers.

Requirements

  • PHP 8.1+
  • Laravel 10.0 / 11.0 / 12.0
  • Spatie Laravel Permission ^6.0

Installation

  1. Install the package via Composer (once published):
composer require arjunyuvanesh/common-auth
  1. Run the automated install command. This will publish the configuration and migrations:
php artisan common-auth:install
  1. Run the database migrations to safely add username and mobile to your users table:
php artisan migrate
  1. Seed the default Spatie roles required by the package:
php artisan common-auth:seed-roles

Setup

1. Update your User Model

Add the HasCommonAuth trait to your App\Models\User class. This automatically injects the Spatie roles and helper methods:

namespace App\Models;

use Arjunyuvanesh\CommonAuth\Traits\HasCommonAuth;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasCommonAuth; // Add this line!
    
    protected $fillable = [
        'name', 'email', 'password', 'username', 'mobile'
    ];
}

2. Configuration

You can modify the package behavior in config/common-auth.php:

return [
    'route_prefix' => 'api/auth', // Change the URL prefix dynamically
    'default_role' => 'User',     // Default role assigned on registration
    
    // Dynamically define what fields are required during registration
    'registration_fields' => [
        'name'     => 'required|string|max:255',
        'mobile'   => 'required|string|unique:users',
        'password' => 'required|string|min:8|confirmed',
    ]
];

API Endpoints

Once installed, the following endpoints are automatically available (prefixed by your config):

  • POST /common-auth/login - Accepts login (email/mobile/username) and password.
  • POST /common-auth/register - Accepts your dynamically configured registration fields.
  • POST /common-auth/logout - Logs out the authenticated user.
  • POST /common-auth/forgot-password - Sends a password reset link (requires email).
  • POST /common-auth/reset-password - Resets the password.

Testing

Run the tests using Orchestra Testbench:

vendor/bin/phpunit

License

The MIT License (MIT).

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固