digitalstate/platform-account-bundle
Installation
composer require digitalstate/platform-account-bundle
Add to config/app.php under ExtraBundles:
DigitalState\PlatformAccountBundle\PlatformAccountBundle::class,
Publish Configuration
php artisan vendor:publish --provider="DigitalState\PlatformAccountBundle\PlatformAccountBundle" --tag="config"
This generates config/platform_account.php with default settings.
Run Migrations
php artisan migrate
The bundle includes migrations for core account tables (e.g., users, user_profiles, auth_tokens).
First Use Case: User Registration
Use the provided controller (AccountController) or extend it:
use DigitalState\PlatformAccountBundle\Controller\AccountController;
Route::post('/register', [AccountController::class, 'register']);
src/Entity/User.php and src/Entity/UserProfile.php define the base models.src/Service/UserService.php handles business logic (e.g., registration, profile updates).src/Event/UserRegisteredEvent.php for extending workflows (e.g., email verification).src/Form/UserRegistrationType.php for customizing registration fields.User Lifecycle
UserRegistrationType to add fields or validation.
$builder->add('custom_field', TextType::class, ['required' => true]);
Authenticator service:
$this->authenticator->login($credentials);
UserProfileService:
$profile = $this->profileService->update($user, ['avatar' => $file]);
Integration with Existing Systems
UserProviderInterface for non-standard auth:
class CustomUserProvider implements UserProviderInterface {
public function retrieveByCredentials(array $credentials) { ... }
}
UserRegisteredEvent or UserUpdatedEvent:
// In a service provider
$this->eventDispatcher->addListener(
UserRegisteredEvent::class,
[YourListener::class, 'handleRegistration']
);
API-First Approach
AccountApiController for REST endpoints:
Route::apiResource('accounts', AccountApiController::class);
src/Serializer/UserNormalizer.php.UserService or Authenticator over direct EntityManager usage.UserRegistrationType or UserProfileType to avoid reinventing validation.AccountBundleTestCase base class for unit/integration tests:
use DigitalState\PlatformAccountBundle\Tests\AccountBundleTestCase;
class MyTest extends AccountBundleTestCase { ... }
Migration Conflicts
users table, run php artisan migrate:status to avoid schema conflicts.Schema::table() in custom migrations to add columns post-install.Event Dispatching
UserRegisteredEvent are dispatched after the user is saved. Override UserService::register() to add pre-save logic:
public function register(array $data) {
$this->dispatchEvent(new UserPreRegisteredEvent($data));
// ... rest of logic
}
Password Hashing
UserPasswordHasherInterface. For custom hashing, bind your implementation:
# config/services.yaml
DigitalState\PlatformAccountBundle\Service\UserService:
arguments:
$passwordHasher: '@your_custom_hasher'
php artisan platform-account:validate-token to debug auth tokens.config/platform_account.php:
'debug' => [
'log_events' => true,
],
Check storage/logs/platform_account.log for event traces.Custom Fields
Add fields to UserProfile via a custom entity:
/**
* @ORM\Entity
*/
class ExtendedUserProfile extends UserProfile {
/**
* @ORM\Column(type="string")
*/
private $customField;
}
Update UserProfileType to include the new field.
Multi-Tenant Support
Override UserService::findUserByEmail() to scope by tenant:
public function findUserByEmail(string $email): ?User {
return $this->userRepository->findOneBy([
'email' => $email,
'tenant_id' => $this->tenantService->getId(),
]);
}
Third-Party Auth
Integrate OAuth via Authenticator:
$this->authenticator->loginWithOAuth(
$providerName,
$accessToken
);
config/platform_account.php:
'verification' => [
'enabled' => false,
],
'password' => [
'min_length' => 12,
'require_uppercase' => true,
],
How can I help you explore Laravel packages today?