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

Users Profile Group Laravel Package

baks-dev/users-profile-group

Symfony/PHP 8.4+ модуль групп профилей пользователя: установка через Composer, команды для первичной настройки и добавления администратора, установка ассетов, рекомендации для composer auto-scripts, миграции Doctrine и тесты PHPUnit.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require baks-dev/users-profile-group
    

    Add to composer.json:

    "scripts": {
        "post-install-cmd": ["@auto-scripts"],
        "post-update-cmd": ["@auto-scripts"],
        "auto-scripts": {
            "baks:assets:install": "symfony-cmd",
            "baks:cache:clear": "symfony-cmd"
        }
    }
    
  2. Initialize Admin: Run these commands in order:

    php artisan baks:users-profile-type:user
    php artisan baks:auth-email:admin
    php artisan baks:users-profile-user:admin
    php artisan baks:users-profile-group:admin
    
  3. Database Setup:

    php artisan doctrine:migrations:diff
    php artisan doctrine:migrations:migrate
    

First Use Case

Create a new user group (e.g., "Premium Users") and assign a user to it:

// In a Laravel controller or command
$user = User::find(1);
$group = Group::create(['name' => 'Premium Users']);
$user->groups()->attach($group);

Implementation Patterns

Core Workflows

  1. Group Management:

    • Use baks:users-profile-group:create to add groups via CLI.
    • Extend Group model (e.g., app/Models/ProfileGroup.php) for custom logic.
  2. User-Group Relationships:

    • Leverage Eloquent relationships:
      // User model
      public function groups()
      {
          return $this->belongsToMany(ProfileGroup::class);
      }
      
      // ProfileGroup model
      public function users()
      {
          return $this->belongsToMany(User::class);
      }
      
  3. Permissions Integration:

    • Gate access in policies:
      public function viewAny(ProfileGroup $group)
      {
          return auth()->user()->groups->contains($group);
      }
      
  4. Asset Handling:

    • Run php artisan baks:assets:install to sync resources (e.g., CSS/JS for group-specific UI).

Integration Tips

  • Symfony Commands: Register in app/Console/Kernel.php:

    protected $commands = [
        \BaksDev\UsersProfileGroup\Console\UsersProfileGroupCommand::class,
        // Other baks commands...
    ];
    
  • Doctrine vs. Eloquent: Use Eloquent for simplicity unless Doctrine-specific features (e.g., DQL) are needed. Bridge with:

    use Doctrine\ORM\EntityManagerInterface;
    $entityManager = app(EntityManagerInterface::class);
    
  • Testing: Run group-specific tests:

    php artisan test --group=users-profile-group
    

Gotchas and Tips

Pitfalls

  1. Doctrine Conflicts:

    • Avoid mixing Doctrine and Eloquent for the same models. Use one ORM per model.
    • If using Eloquent, disable Doctrine’s proxy generation for those models.
  2. CLI Command Overrides:

    • Custom commands with the same name (e.g., group:create) will conflict. Prefix with baks: or namespace:
      php artisan baks:users-profile-group:create
      
  3. Asset Paths:

    • baks:assets:install assumes default paths. Override in config/baks.php:
      'assets' => [
          'path' => public_path('baks-assets'),
      ],
      
  4. Migration Order:

    • Run Laravel migrations before Doctrine migrations to avoid foreign key errors.

Debugging

  • Command Issues: Enable Symfony’s debug mode:

    php artisan --env=local baks:users-profile-group:admin
    
  • Database Errors: Check Doctrine logs:

    // In config/services.php
    'doctrine' => [
        'log' => true,
    ],
    

Extension Points

  1. Custom Groups: Extend the Group model:

    namespace App\Models;
    
    use BaksDev\UsersProfileGroup\Models\Group as BaseGroup;
    
    class ProfileGroup extends BaseGroup
    {
        protected $table = 'profile_groups';
        // Custom fields/methods
    }
    
  2. Event Listeners: Listen for group/user events:

    // In EventServiceProvider
    protected $listen = [
        \BaksDev\UsersProfileGroup\Events\UserAssignedToGroup::class => [
            \App\Listeners\LogGroupAssignment::class,
        ],
    ];
    
  3. API Endpoints: Use Laravel’s API resources:

    Route::get('/groups', function () {
        return Group::with('users')->get();
    });
    

Tips

  • Performance: Cache group memberships:

    $user->groups->fresh();
    
  • Localization: Translate CLI output by extending commands:

    public function handle()
    {
        $this->info(__('Group created: :name', ['name' => $this->groupName]));
    }
    
  • Backup: Include baks tables in backups (e.g., users_profile_groups).

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky