Weave Code
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

User Bundle Laravel Package

barygi/user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require friendsofsymfony/user-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        FriendsOfSymfony\UserBundle\FOSUserBundle::class => ['all' => true],
    ];
    
  2. Database Configuration: Ensure your User entity extends FOS\UserBundle\Model\User (or UserInterface). Example:

    use FOS\UserBundle\Model\User as BaseUser;
    
    class User extends BaseUser
    {
        // Custom fields here
    }
    
  3. First Use Case: Generate a CRUD controller for User:

    php bin/console make:crud User
    

    Enable registration routes in config/routes.yaml:

    fos_user:
        resource: "@FOSUserBundle/Resources/config/routing/all.xml"
        prefix: /auth
    

Implementation Patterns

Core Workflows

  1. User Registration:

    • Extend FOSUserBundle's registration form:
      use FOS\UserBundle\Form\Type\RegistrationFormType;
      
      $builder->add('customField', TextType::class);
      
    • Override registration template (templates/FOSUserBundle/registration/register.html.twig).
  2. Password Reset:

    • Use built-in reset workflow:
      $dispatcher->dispatch(
          FOSUserEvents::PASSWORD_RESET_INITIALIZE,
          new GetResponseUserPasswordResetEvent($user, $request)
      );
      
    • Customize email templates in templates/FOSUserBundle/ResetPassword/email.txt.twig.
  3. Authentication Integration:

    • Configure security.yaml to use fos_user.user_provider.username_email:
      providers:
          fos_userbundle:
              id: fos_user.user_provider.username_email
      

Common Patterns

  • Custom User Fields: Add fields to User entity and update RegistrationFormType:
    $builder->add('phone', TextType::class);
    
  • Event Listeners: Subscribe to events (e.g., FOSUserEvents::REGISTRATION_COMPLETED) in services.yaml:
    services:
        App\EventListener\UserListener:
            tags:
                - { name: kernel.event_listener, event: fos_user.registration.completed, method: onRegistrationComplete }
    

Gotchas and Tips

Pitfalls

  1. Route Conflicts: Ensure fos_user routes don’t clash with existing routes (e.g., /register). Use prefix in routes.yaml.

  2. Doctrine Migrations: After adding custom fields, run:

    php bin/console doctrine:schema:update --force
    
  3. Email Configuration: Verify fos_user.mailer service is properly configured in config/packages/fos_user.yaml:

    fos_user:
        from_email:
            address: "noreply@example.com"
            sender_name: "App Name"
    

Debugging Tips

  • Event Debugging: Enable Symfony’s event dispatcher debug mode:

    $dispatcher->addListener(FOSUserEvents::REGISTRATION_COMPLETED, function($event) {
        dump($event->getUser());
    });
    
  • Form Validation: Use fos_user.registration.form.type to debug form errors:

    $form = $this->createForm(FOSUserBundle::getRegistrationFormType(), $user);
    

Extension Points

  1. Custom User Provider: Extend FOS\UserBundle\Model\UserManager for custom logic:

    class CustomUserManager extends UserManager
    {
        public function updateUser(UserInterface $user, array $data)
        {
            // Custom logic
            parent::updateUser($user, $data);
        }
    }
    
  2. Template Overrides: Copy templates from vendor/friendsofsymfony/user-bundle/Resources/views to templates/FOSUserBundle/ to override defaults.

  3. Security Integration: Use fos_user.user_provider in security.yaml for custom authentication logic:

    firewalls:
        main:
            form_login:
                provider: fos_userbundle
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui