Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Module Users Laravel Package

cvepdb-cms/module-users

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require cvepdb-cms/module-users
    

    Ensure the module is registered in config/app.php under modules (if using a modular Laravel setup).

  2. Publish Config & Migrations

    php artisan vendor:publish --provider="Cvepdb\Users\UsersServiceProvider" --tag="config"
    php artisan vendor:publish --provider="Cvepdb\Users\UsersServiceProvider" --tag="migrations"
    

    Run migrations:

    php artisan migrate
    
  3. First Use Case: User Registration Use the provided facade or service class to create a user:

    use Cvepdb\Users\Facades\Users;
    
    $user = Users::create([
        'name' => 'John Doe',
        'email' => '[email protected]',
        'password' => bcrypt('secure123'),
    ]);
    

Implementation Patterns

Core Workflows

  1. User Management

    • CRUD Operations: Use the Users facade or UserService for create/read/update/delete.
      $user = Users::find(1);
      Users::update(1, ['role' => 'admin']);
      
    • Role-Based Access: Leverage the built-in role system (if implemented) via:
      Users::assignRole($userId, 'editor');
      
  2. Authentication Integration

    • Extend Laravel’s default auth by overriding AuthServiceProvider:
      public function boot()
      {
          $this->registerPolicies();
          Users::extendAuth(); // If the module provides this method
      }
      
  3. API Endpoints

    • Use the module’s HTTP controllers (if provided) or create custom routes:
      Route::prefix('api/users')->group(function () {
          Route::get('/', [UsersController::class, 'index']);
      });
      
  4. Event Listeners

    • Listen to user-related events (e.g., UserRegistered, UserUpdated):
      Users::listen('UserRegistered', function ($user) {
          // Send welcome email
      });
      

Gotchas and Tips

Pitfalls

  1. Migration Conflicts

    • If the module’s users table conflicts with Laravel’s default, rename the module’s table in its config:
      'table' => 'cvepdb_users',
      
  2. Authentication Overrides

    • If the module replaces Laravel’s default User model, ensure middleware (auth, auth:admin) is updated to use the module’s guard:
      'guards' => [
          'web' => ['driver' => 'session', 'provider' => 'cvepdb-users'],
      ],
      
  3. Role System Quirks

    • If roles aren’t working, verify the roles table exists and the user_role pivot table is set up correctly in migrations.

Debugging Tips

  • Log User Actions: Use Laravel’s logging to trace user operations:
    \Log::info('User created', ['user' => $user->toArray()]);
    
  • Check Module Events: Enable debug mode to see fired events:
    Users::enableDebug();
    

Extension Points

  1. Custom Fields Add extra fields to the users table via a new migration, then extend the User model:

    class User extends \Cvepdb\Users\Models\User
    {
        protected $casts = [
            'is_active' => 'boolean',
        ];
    }
    
  2. Validation Rules Override validation logic in a service provider:

    Users::extendValidation(function ($validator) {
        $validator->extend('unique_email', function ($attribute, $value, $parameters, $validator) {
            return !Users::where('email', $value)->exists();
        });
    });
    
  3. API Resources Extend the module’s UserResource for custom API responses:

    namespace App\Http\Resources;
    use Cvepdb\Users\Http\Resources\UserResource as BaseUserResource;
    
    class UserResource extends BaseUserResource
    {
        public function toArray($request)
        {
            $array = parent::toArray($request);
            $array['custom_field'] = $this->custom_field;
            return $array;
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
likyly/sdk
tdt/input
coreation/php-shapefile
coreation/gisconverter
primix/widgets
primix/notifications
primix/actions
primix/tables
primix/details
primix/forms
primix/support
marcelgwerder/laravel-api-handler
firebrikdotcom/conveyor-laravel-broadcaster
kanata-php/conveyor-laravel-broadcaster
alish/short-message
sonrac/lumen-league-oauth2
pushery/sanctum-hardening-for-laravel
evanschleret/laravel-uuidable
yigit-serin/laravel-openvidu
adachsoft/command-executor-lib