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 Manager Laravel Package

com.panda180.laravel/user-manager

Simple Laravel package to retrieve users from your database. Install via Composer and call UserManager->getUsers() to fetch all users quickly. Works with Laravel 8+ and PHP 7.4+.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require baraaha/user-manager
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="Baraaha\UserManager\UserManagerServiceProvider"
    
  2. Basic Usage Fetch all users:

    use Baraaha\UserManager\Facades\UserManager;
    
    $users = UserManager::all();
    
  3. First Use Case Retrieve a single user by ID:

    $user = UserManager::find(1);
    

Key Files to Review

  • Config: config/user-manager.php (if published)
  • Facade: app/Facades/UserManager.php
  • Service Provider: vendor/baraaha/user-manager/src/UserManagerServiceProvider.php

Implementation Patterns

Core Workflows

  1. Fetching Users

    // Get all users
    $users = UserManager::all();
    
    // Get paginated users
    $users = UserManager::paginate(10);
    
    // Get users with eager loading
    $users = UserManager::with('roles')->get();
    
  2. Filtering and Searching

    // Filter by role
    $users = UserManager::whereHas('roles', 'name', 'admin')->get();
    
    // Search by name
    $users = UserManager::search('John')->get();
    
  3. Integration with Controllers

    use Baraaha\UserManager\Facades\UserManager;
    
    public function index()
    {
        $users = UserManager::paginate(request('per_page', 10));
        return view('users.index', compact('users'));
    }
    

Advanced Patterns

  • Custom Queries Extend the package by binding custom queries:

    UserManager::query()->where('active', true)->get();
    
  • Event Hooks Listen for user events (if the package supports them):

    UserManager::on('user.created', function ($user) {
        // Handle user creation
    });
    
  • API Integration Use the facade in API resources:

    public function toArray($request)
    {
        return [
            'users' => UserManager::all()->toArray(),
        ];
    }
    

Gotchas and Tips

Common Pitfalls

  1. No Built-in Auth Integration

    • The package does not handle authentication (e.g., Auth::user()). Use Laravel’s built-in auth for sessions/permissions.
  2. No Default Model Binding

    • If you expect UserManager::find(1) to return a User model, ensure the package is configured to use your App\Models\User (check the config or service provider).
  3. No Soft Deletes by Default

    • If your User model uses soft deletes, ensure the package respects this:
    $users = UserManager::withTrashed()->get(); // If needed
    
  4. Query Scope Conflicts

    • If you define global scopes on your User model (e.g., globalScope), they may interfere with package queries. Temporarily remove them when using UserManager:
    $users = UserManager::withoutGlobalScopes(function () {
        return UserManager::get();
    });
    

Debugging Tips

  • Check the Underlying Query Use Laravel’s query logging to inspect SQL:

    DB::enableQueryLog();
    $users = UserManager::all();
    dd(DB::getQueryLog());
    
  • Verify Config Values If methods return unexpected results, inspect the published config:

    config('user-manager.model'); // Should match your User model
    

Extension Points

  1. Customize the Model Override the default model in the config:

    'model' => App\Models\CustomUser::class,
    
  2. Add Custom Methods Extend the facade or service class:

    // In a service provider
    UserManager::extend(function ($app) {
        return new CustomUserManager($app);
    });
    
  3. Modify Query Behavior Bind custom query builders:

    UserManager::macro('activeUsers', function () {
        return $this->query()->where('active', true);
    });
    // Usage: UserManager::activeUsers()->get();
    
  4. Handle Events If the package emits events, listen for them in EventServiceProvider:

    protected $listen = [
        'Baraaha\UserManager\Events\UserCreated' => [
            'App\Listeners\LogUserCreation',
        ],
    ];
    
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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager