baks-dev/users-profile-group
Symfony/PHP 8.4+ модуль групп профилей пользователя: установка через Composer, команды для первичной настройки и добавления администратора, установка ассетов, рекомендации для composer auto-scripts, миграции Doctrine и тесты PHPUnit.
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"
}
}
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
Database Setup:
php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
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);
Group Management:
baks:users-profile-group:create to add groups via CLI.Group model (e.g., app/Models/ProfileGroup.php) for custom logic.User-Group Relationships:
// User model
public function groups()
{
return $this->belongsToMany(ProfileGroup::class);
}
// ProfileGroup model
public function users()
{
return $this->belongsToMany(User::class);
}
Permissions Integration:
public function viewAny(ProfileGroup $group)
{
return auth()->user()->groups->contains($group);
}
Asset Handling:
php artisan baks:assets:install to sync resources (e.g., CSS/JS for group-specific UI).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
Doctrine Conflicts:
CLI Command Overrides:
group:create) will conflict. Prefix with baks: or namespace:
php artisan baks:users-profile-group:create
Asset Paths:
baks:assets:install assumes default paths. Override in config/baks.php:
'assets' => [
'path' => public_path('baks-assets'),
],
Migration Order:
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,
],
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
}
Event Listeners: Listen for group/user events:
// In EventServiceProvider
protected $listen = [
\BaksDev\UsersProfileGroup\Events\UserAssignedToGroup::class => [
\App\Listeners\LogGroupAssignment::class,
],
];
API Endpoints: Use Laravel’s API resources:
Route::get('/groups', function () {
return Group::with('users')->get();
});
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).
How can I help you explore Laravel packages today?