Install the Bundle (via Composer):
composer require connectholland/user-bundle
Note: This bundle is Symfony-based, but can be adapted for Laravel via Symfony Bridge or by leveraging its core logic (e.g., OAuth, JWT, and user management) in a Laravel context.
Configure Environment Variables (.env):
USERBUNDLE_FROM_EMAILADDRESS=your@email.com
JWT_SECRET_KEY=path/to/private.pem
JWT_PUBLIC_KEY=path/to/public.pem
JWT_PASSPHRASE=your-passphrase
Set Up Database & Migrations:
User entity mirroring this structure and configure Doctrine via config/packages/doctrine.yaml.First Use Case: CLI User Creation
php artisan connectholland:user:create user@example.com P@ssw0rd --role=ROLE_USER
For Laravel, adapt this command via a custom Artisan command or use Laravel’s make:user with similar logic.
| Feature | Laravel Equivalent/Integration Point |
|---|---|
| OAuth | Use hwi/oauth-bundle (Symfony) or Laravel’s socialiteproviders |
| JWT Authentication | Replace with Laravel’s typset/laravel-jwt-auth or spatie/laravel-jwt |
| Email Verification | Adapt the UserConfirmationController logic into Laravel’s Illuminate\Auth\Events\Verified |
| API Endpoints | Override routes in routes/api.php to match Symfony’s connectholland_user.yaml |
/api/register (POST).FormRequest).UserCreatedEvent (adapt Symfony’s UserBundleEvents::USER_CREATED).Twig-based template or convert to Laravel’s Mailable).200 (no body) due to the bundle’s fix for API Platform 2.x.// routes/api.php
Route::post('/register', [UserController::class, 'register']);
// app/Http/Controllers/UserController.php
public function register(RegisterRequest $request) {
$user = User::create($request->validated());
event(new Registered($user)); // Trigger email
return response()->noContent(); // 200 + no body
}
composer require socialiteproviders/google
.env:
GOOGLE_CLIENT_ID=your_id
GOOGLE_CLIENT_SECRET=your_secret
use Laravel\Socialite\Facades\Socialite;
public function redirectToGoogle() {
return Socialite::driver('google')->redirect();
}
public function handleGoogleCallback() {
$user = Socialite::driver('google')->user();
// Link to existing user or create new
}
Replace Symfony’s HWI logic with Laravel’s socialiteproviders.composer require typset/laravel-jwt-auth
config/jwt.php and generate keys:
php artisan jwt:secret
Route::middleware('auth:api')->group(function () {
Route::get('/account', [AccountController::class, 'details']);
});
Mirror Symfony’s lexik/jwt-authentication-bundle behavior.php artisan make:model User -m --api
use Illuminate\Foundation\Auth\User as Authenticatable;
use ConnectHolland\UserBundle\Entity\Traits\Timestampable; // Hypothetical trait
class User extends Authenticatable {
use Timestampable;
// Add custom fields (e.g., `profilePicture`)
}
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('profile_picture')->nullable();
// ... other fields
});
php artisan make:controller Auth/ResetPasswordController
// app/Mail/ResetPasswordMail.php
public function build() {
return $this->subject('Reset Password')
->markdown('emails.password_reset');
}
Adapt Symfony’s UserBundle email templates to Laravel’s markdown system.API Platform Version Mismatch:
200 response fix only applies to API Platform 2.x. If using 3.x, responses may behave differently (e.g., 201 for POSTs is now standard).status: 200 in API resource metadata:
# config/api_platform/resources.yaml
App\Entity\User:
attributes:
status: 200
Doctrine ORM vs. Eloquent:
EntityManager). Instead:
UserBundle\Repository\UserRepository with Laravel’s User::query().OAuth Provider Quirks:
HWI bundle expects specific provider configurations. In Laravel:
socialiteproviders/google matches Symfony’s USERBUNDLE_OAUTH_GOOGLE_SCOPE.hd: "your-domain.com" to Google’s config if using domain restriction.Email Templates:
{# Symfony Twig #}
<a href="{{ url }}">Verify Email</a>
{# Laravel Blade #}
<a href="{{ $url }}">Verify Email</a>
JWT Key Paths:
config/jwt/private.pem). In Laravel:
storage/app/jwt/ and use relative paths:
JWT_SECRET_KEY=storage/app/jwt/private.pem
Check HTTP Responses:
dd(response()->getContent()) to inspect API responses. Ensure POSTs return 200 (not 201) for non-resource operations.OAuth Debugging:
Socialite::with('google')->scopes(['email'])->redirect();
USERBUNDLE_OAUTH_GOOGLE_ID).Email Delivery:
Mail::fake():
Mail::fake();
event(new Registered($user));
Mail::assertSent(ResetPasswordMail::class);
Doctrine vs. Eloquent Conflicts:
EntityManager calls in controllers.SchemaTool).Custom User Fields:
User model in Laravel:
class User extends Authenticatable {
protected $casts = [
'is_active' => 'boolean',
'last_login_at' => 'datetime',
];
}
Override Email Logic:
UserConfirmationController with a Laravel EventListener:
public function handle(Registered $event) {
Mail::to($event->user->email)->send(new VerifyEmail($event->user));
}
API Response Customization:
ApiPlatform metadata in Laravel:How can I help you explore Laravel packages today?