properos/laravel-users 问题修复 & 功能扩展

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

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

properos/laravel-users

Composer 安装命令:

composer require properos/laravel-users

包简介

Users package

README 文档

README

Laravel 11 package for user management, authentication, authorization (roles & permissions), and user profiles.

Requirements

  • Laravel: 11.x
  • PHP: 8.2+
  • Database: MySQL 5.7+ or MariaDB 10.3+

Dependencies

This package requires the following packages:

Package Version Purpose
laravel/sanctum ^4.0 API authentication
intervention/image ^3.0 Image processing (avatars, uploads)
intervention/image-laravel ^1.0 Laravel integration for Intervention Image
laravel/ui ^4.0 Authentication scaffolding
laravel/socialite ^5.0 Social authentication (optional)

Installation

1. Install the package

composer require properos/laravel-users

2. Publish configuration files

php artisan vendor:publish --provider="Properos\Users\UsersServiceProvider"

3. Run migrations

php artisan migrate

This will create the following tables:

  • users
  • user_addresses
  • user_profiles
  • roles
  • permissions
  • user_roles
  • user_permissions
  • role_permissions
  • api_credentials
  • user_activity_logs

4. Run seeders (optional)

Add the following to database/seeders/DatabaseSeeder.php:

use Properos\Users\Database\Seeders\RolesPermissionsTableSeeder;
use Properos\Users\Database\Seeders\UsersTableSeeder;

public function run(): void
{
    $this->call([
        RolesPermissionsTableSeeder::class,
        UsersTableSeeder::class,
    ]);
}

Then run:

php artisan db:seed

Configuration

1. Database Configuration

In config/database.php, ensure MySQL configuration uses:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8',
    'collation' => 'utf8_general_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => 'InnoDB',
],

2. Authentication Configuration

In config/auth.php, update the guards and providers:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'sanctum',
        'provider' => 'users',
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => \Properos\Users\Models\User::class,
    ],
],

3. Service Providers

In config/app.php, add to the providers array:

Laravel\Socialite\SocialiteServiceProvider::class,

4. Middleware Registration

In app/Http/Kernel.php, register the middleware:

'role' => \Properos\Users\Middlewares\RoleMiddleware::class,
'permission' => \Properos\Users\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Properos\Users\Middlewares\RoleOrPermissionMiddleware::class,

5. Social Authentication (Optional)

If you want to enable social authentication (Facebook, Google), install Socialite:

composer require laravel/socialite

Add to config/services.php:

'facebook' => [
    'client_id' => env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect' => env('FACEBOOK_CALLBACK', 'http://your-app.com/auth/facebook/callback')
],

'google' => [
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' => env('GOOGLE_CALLBACK', 'http://your-app.com/auth/google/callback')
],

Add to your .env:

FACEBOOK_CLIENT_ID=your-app-id
FACEBOOK_CLIENT_SECRET=your-app-secret
FACEBOOK_CALLBACK=http://your-app.com/auth/facebook/callback

GOOGLE_CLIENT_ID=your-app-id
GOOGLE_CLIENT_SECRET=your-app-secret
GOOGLE_CALLBACK=http://your-app.com/auth/google/callback

6. Environment Variables

Add to your .env:

# Laravel Mix / Vite
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

MIX_HOST="${DOMAIN}"
MIX_API_BASE_URL=
MIX_CDN_URL=

MIX_ADMIN_WEB_PREFIX='/admin'
MIX_ADMIN_WEB_API_PREFIX='/api/admin'

Asset Compilation

1. Install npm dependencies

npm install
npm install moment --save

2. Configure webpack.mix.js

Add to webpack.mix.js:

.js('resources/assets/js/be/modules/users/js/user.js', 'public/be/js/modules/user.js')

3. Configure bootstrap.js

In resources/assets/bootstrap.js, add:

import Helpers from './misc/helpers'

window.moment = require('moment')
window.Vue = require('vue');
window.Helpers = Helpers;

4. Compile assets

npm run watch
# or
npm run prod

Usage

Using Models

use Properos\Users\Models\User;
use Properos\Users\Models\Role;
use Properos\Users\Models\Permission;

// Get all users
$users = User::all();

// Find user by ID
$user = User::find(1);

// Get user roles
$roles = $user->roles;

// Get user permissions
$permissions = $user->permissions;

Using Routes

Add to routes/web.php:

use Illuminate\Support\Facades\Route;

Route::get('/admin/dashboard', function(){
    return view('be.index');
})->middleware(['auth', 'role:admin']);

Route::get('/admin/users', [UserController::class, 'index'])
    ->middleware(['auth', 'permission:users.view']);

Using Middleware

// Role-based
Route::middleware(['role:admin'])->group(function () {
    // Admin only routes
});

// Permission-based
Route::middleware(['permission:users.edit'])->group(function () {
    // Users edit only routes
});

// Role OR Permission
Route::middleware(['role_or_permission:super-admin'])->group(function () {
    // Routes accessible by super-admin role OR super-admin permission
});

Using Classes

use Properos\Users\Classes\CUser;

$cuser = new CUser();

// Create user
$user = $cuser->create([
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => 'john@example.com',
    'password' => 'password123',
    'avatar' => $uploadedFile // Optional UploadedFile
]);

// Assign role
$cuser->assignRole([
    'user_id' => $user->id,
    'role_id' => 1
]);

// Assign permission
$cuser->assignPermission([
    'user_id' => $user->id,
    'permission_id' => 1
]);

// Change password
$cuser->changePassword([
    'user_id' => $user->id,
    'password' => 'newpassword123',
    'password_confirmation' => 'newpassword123'
]);

Features

User Management

  • Create, read, update, delete users
  • User profiles and addresses
  • Avatar upload and processing
  • User activity logging

Authentication

  • Email/password authentication
  • Social authentication (Facebook, Google)
  • Password reset
  • API authentication via Sanctum

Authorization

  • Role-based access control (RBAC)
  • Permission-based access control
  • Flexible role/permission assignment
  • Middleware for route protection

User Profile

  • First name, last name, email, phone
  • Company information
  • Avatar management
  • Address management

Activity Logging

  • Automatic user activity tracking
  • Login/logout logging
  • Custom action logging

Troubleshooting

Migration errors

If you get migration errors about duplicate tables:

php artisan migrate:rollback --step=1
# Then check if tables exist and drop them if needed
php artisan migrate

Service provider not found

Make sure the service provider is registered in config/app.php:

Properos\Users\UsersServiceProvider::class,

Middleware not working

Ensure middleware is registered in app/Http/Kernel.php with the correct aliases.

Image upload not working

  1. Check that intervention/image and intervention/image-laravel are installed
  2. Ensure the public disk is configured in config/filesystems.php
  3. Check file permissions on storage/app/public

Vue components not rendering

  1. Ensure assets are compiled: npm run prod
  2. Check that webpack.mix.js is configured correctly
  3. Verify that bootstrap.js includes the required dependencies

Sanctum authentication not working

  1. Ensure laravel/sanctum is installed
  2. Run php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
  3. Add Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful to app/Http/Kernel.php
  4. Configure stateful domains in config/sanctum.php

Breaking Changes from Previous Versions

  • Laravel Version: Requires Laravel 11.x (minimum)
  • PHP Version: Requires PHP 8.2+
  • Intervention Image: Updated to v3 with new API
  • Database Collation: Default collation is now utf8_general_ci

License

MIT License. See LICENSE file for details.

properos/laravel-users 适用场景与选型建议

properos/laravel-users 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Users」 「laravel」 「properos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 properos/laravel-users 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 properos/laravel-users 我们能提供哪些服务?
定制开发 / 二次开发

基于 properos/laravel-users 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-01