l5starter/user-management
Laravel 5.4 user management module for L5Starter admin. Installs via Composer with a service provider, publishable config, and seeders for users and role assignments. Includes an admin sidebar menu entry for managing users.
Installation Add the package via Composer:
composer require l5starter/user-management:5.4.x-dev
Register the service provider in config/app.php:
'providers' => [
// ...
L5Starter\UserManagement\UserManagementServiceProvider::class,
],
Publish Configuration & Migrations Run the publisher command to generate config and migrations:
php artisan vendor:publish --provider="L5Starter\UserManagement\UserManagementServiceProvider"
Then migrate your database:
php artisan migrate
Seed Initial Data Populate the database with default users and roles:
php artisan db:seed --class=UsersTableSeeder
php artisan db:seed --class=UserHasRolesTableSeeder
First Use Case: User CRUD Access the admin panel for users via the generated route:
php artisan route:list | grep admin.users
Navigate to /admin/users to interact with the built-in admin interface.
User Management
User model (likely extended from L5Starter\UserManagement\Models\User).
$user = User::create([
'name' => 'John Doe',
'email' => 'john@example.com',
'password' => bcrypt('password'),
]);
hasRole() and attachRole() methods (assuming role-based permissions are implemented).
$user->attachRole('admin'); // If using a role system
Authentication & Authorization
php artisan make:auth
AuthenticatesUsers trait in your LoginController to use the custom User model:
protected $redirectTo = '/admin/dashboard';
protected $username = 'email'; // Use email for login
Admin Panel Integration
resources/views/vendor/l5starter/admin/partials/sidebar.blade.php to expose the user management section.php artisan vendor:publish --tag=l5starter-views
API Endpoints (if applicable)
routes/api.php:
Route::middleware('auth:api')->group(function () {
Route::resource('users', 'UserController');
});
Customize User Model
Extend the default User model to add custom fields or logic:
namespace App;
use L5Starter\UserManagement\Models\User as BaseUser;
class User extends BaseUser
{
protected $fillable = ['name', 'email', 'password', 'custom_field'];
}
Event Listeners
Listen for user-related events (e.g., registered, updated) to trigger actions like notifications:
// In EventServiceProvider
protected $listen = [
'L5Starter\UserManagement\Events\UserRegistered' => [
'App\Listeners\SendWelcomeEmail',
],
];
Policy-Based Authorization Use Laravel’s policies to restrict access:
php artisan make:policy UserPolicy --model=User
Then attach the policy to the User model in AuthServiceProvider.
Localization Override translations by publishing the language files:
php artisan vendor:publish --tag=l5starter-translations
Then extend resources/lang/vendor/l5starter/.
Namespace Conflicts
User as a model name. Ensure your App\User does not conflict by either:
User model (e.g., App\Models\User).AppServiceProvider:
public function boot()
{
\App::bind('L5Starter\UserManagement\Models\User', function () {
return new \App\Models\User;
});
}
Migration Overwrites
users table, manually merge the package’s migrations to avoid conflicts. Check database/migrations/ for overlapping columns.Route Caching
php artisan route:clear
Middleware Dependencies
auth.admin. Ensure these are registered in app/Http/Kernel.php before use.Check Published Config
Verify the published config at config/l5starter.php matches your expectations. Override values as needed:
'default_role' => 'user', // Example override
Log User Actions Add logging to debug user-related operations:
\Log::info('User created', ['user' => $user->toArray()]);
Test Role Assignments If roles aren’t working, check:
UserHasRoles pivot table exists.hasRole() method is correctly implemented (may need to extend the model).Custom Fields
Add fields to the users table via migration, then update the admin form:
// In UserController (if extending)
public function fields()
{
return parent::fields() + ['custom_field' => 'text'];
}
API Resources Extend the default API resource for users:
php artisan make:resource UserResource --model=User
Then override the toArray() method to include/exclude fields.
Custom Admin Views
Override the admin panel views by copying from vendor/l5starter/user-management/resources/views to resources/views/vendor/l5starter/admin/.
Seeding Extensions Extend the seeders to include default users with roles:
// In UsersTableSeeder
$user = User::create([...]);
$user->attachRole('admin');
How can I help you explore Laravel packages today?