Installation
composer require cvepdb-cms/module-users
Ensure the module is registered in config/app.php under modules (if using a modular Laravel setup).
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
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'),
]);
User Management
Users facade or UserService for create/read/update/delete.
$user = Users::find(1);
Users::update(1, ['role' => 'admin']);
Users::assignRole($userId, 'editor');
Authentication Integration
AuthServiceProvider:
public function boot()
{
$this->registerPolicies();
Users::extendAuth(); // If the module provides this method
}
API Endpoints
Route::prefix('api/users')->group(function () {
Route::get('/', [UsersController::class, 'index']);
});
Event Listeners
UserRegistered, UserUpdated):
Users::listen('UserRegistered', function ($user) {
// Send welcome email
});
Migration Conflicts
users table conflicts with Laravel’s default, rename the module’s table in its config:
'table' => 'cvepdb_users',
Authentication Overrides
User model, ensure middleware (auth, auth:admin) is updated to use the module’s guard:
'guards' => [
'web' => ['driver' => 'session', 'provider' => 'cvepdb-users'],
],
Role System Quirks
roles table exists and the user_role pivot table is set up correctly in migrations.\Log::info('User created', ['user' => $user->toArray()]);
Users::enableDebug();
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',
];
}
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();
});
});
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;
}
}
How can I help you explore Laravel packages today?