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+.
Installation
composer require baraaha/user-manager
Publish the config file (if needed):
php artisan vendor:publish --provider="Baraaha\UserManager\UserManagerServiceProvider"
Basic Usage Fetch all users:
use Baraaha\UserManager\Facades\UserManager;
$users = UserManager::all();
First Use Case Retrieve a single user by ID:
$user = UserManager::find(1);
config/user-manager.php (if published)app/Facades/UserManager.phpvendor/baraaha/user-manager/src/UserManagerServiceProvider.phpFetching Users
// Get all users
$users = UserManager::all();
// Get paginated users
$users = UserManager::paginate(10);
// Get users with eager loading
$users = UserManager::with('roles')->get();
Filtering and Searching
// Filter by role
$users = UserManager::whereHas('roles', 'name', 'admin')->get();
// Search by name
$users = UserManager::search('John')->get();
Integration with Controllers
use Baraaha\UserManager\Facades\UserManager;
public function index()
{
$users = UserManager::paginate(request('per_page', 10));
return view('users.index', compact('users'));
}
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(),
];
}
No Built-in Auth Integration
Auth::user()). Use Laravel’s built-in auth for sessions/permissions.No Default Model Binding
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).No Soft Deletes by Default
User model uses soft deletes, ensure the package respects this:$users = UserManager::withTrashed()->get(); // If needed
Query Scope Conflicts
User model (e.g., globalScope), they may interfere with package queries. Temporarily remove them when using UserManager:$users = UserManager::withoutGlobalScopes(function () {
return UserManager::get();
});
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
Customize the Model Override the default model in the config:
'model' => App\Models\CustomUser::class,
Add Custom Methods Extend the facade or service class:
// In a service provider
UserManager::extend(function ($app) {
return new CustomUserManager($app);
});
Modify Query Behavior Bind custom query builders:
UserManager::macro('activeUsers', function () {
return $this->query()->where('active', true);
});
// Usage: UserManager::activeUsers()->get();
Handle Events
If the package emits events, listen for them in EventServiceProvider:
protected $listen = [
'Baraaha\UserManager\Events\UserCreated' => [
'App\Listeners\LogUserCreation',
],
];
How can I help you explore Laravel packages today?