black/user-bundle
WIP Laravel user management bundle for handling users, authentication-related features, and common account workflows. Early-stage package; APIs and behavior may change as development continues.
Installation Add the package via Composer:
composer require black/user-bundle
Publish the migration and config files:
php artisan vendor:publish --provider="Black\UserBundle\UserBundleServiceProvider"
Run migrations:
php artisan migrate
First Use Case: User Registration
Use the User model (auto-registered via the bundle) and its traits:
use Black\UserBundle\Models\User;
$user = User::create([
'email' => 'user@example.com',
'password' => bcrypt('secure123'),
'name' => 'John Doe',
]);
Where to Look First
app/Models/User.php (auto-generated by the bundle).Black\UserBundle\Traits\* for reusable logic (e.g., HasRoles, HasPermissions).app/Http/Middleware/Authenticate.php (if extended by the bundle).routes/web.php (for auth endpoints like register, login).Authentication Use the bundle’s built-in guards (if configured). Example login logic:
use Black\UserBundle\Services\AuthService;
$auth = app(AuthService::class);
$user = $auth->attempt('email@example.com', 'password');
Role/Permission Management
Assign roles to users via the HasRoles trait:
$user->roles()->attach(['admin', 'editor']);
Check permissions:
if ($user->can('edit_articles')) { ... }
API Integration
Extend the UserResource (if provided) for API responses:
use Black\UserBundle\Http\Resources\UserResource;
return new UserResource($user);
Event Listeners
Listen to user events (e.g., user.created):
// In EventServiceProvider
protected $listen = [
'user.created' => [
'App\Listeners\SendWelcomeEmail',
],
];
User model to add fields:
class User extends \Black\UserBundle\Models\User
{
protected $casts = [
'is_active' => 'boolean',
];
}
UserRequest (if available) or extend it:
use Black\UserBundle\Http\Requests\UserRequest;
class CustomUserRequest extends UserRequest { ... }
AuthService or use the UserFactory (if provided):
$user = User::factory()->create();
Archived Status The package is archived (no active maintenance). Expect:
Incomplete Features
Migration Conflicts
The bundle’s migrations may clash with existing users tables. Backup first:
php artisan migrate:status
dd(app('config')->get('user-bundle.models.user'));
dd(config('user-bundle'));
\DB::enableQueryLog();
$user->roles(); // Trigger query
\DB::getQueryLog();
Override Models
Replace the default User model in config/user-bundle.php:
'models' => [
'user' => App\Models\CustomUser::class,
],
Custom Auth Logic
Extend AuthService:
class CustomAuthService extends \Black\UserBundle\Services\AuthService {
public function attempt($email, $password) {
// Custom logic
}
}
Bind it in a service provider:
$this->app->bind(
\Black\UserBundle\Services\AuthService::class,
CustomAuthService::class
);
Add Policies Use Laravel’s policy system:
use Black\UserBundle\Models\User;
class PostPolicy {
public function update(User $user, Post $post) {
return $user->can('edit_posts');
}
}
php artisan tinker
>>> $user = \Black\UserBundle\Models\User::first();
>>> $user->roles
try-catch for future-proofing.How can I help you explore Laravel packages today?