User Management System is a web-based application that manages user records and provides secure role-based access for users and administrators. Built with Laravel 12, it features a modern interface using Blade and Tailwind CSS (RetroUI) and ensures data integrity with a MySQL database.
This module handles all standard user interactions, ensuring a smooth and secure experience.
A dedicated control center for administrators to manage the application and its users.
This project is configured to run with Laravel Sail, a light-weight command-line interface for interacting with Laravel’s default Docker development environment.
git clone https://github.com/prayangshu/laravel-user-management.git
cd laravel-user-management
composer install
If you do not have PHP/Composer installed locally, you can use a small Docker container to install dependencies:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php84-composer:latest \
composer install --ignore-platform-reqs
cp .env.example .env
./vendor/bin/sail up -d
./vendor/bin/sail artisan key:generate
./vendor/bin/sail artisan migrate --seed
./vendor/bin/sail npm install
./vendor/bin/sail npm run build
Access the app at http://localhost.
./vendor/bin/sail up -d./vendor/bin/sail down./vendor/bin/sail artisan <command>./vendor/bin/sail composer <command>./vendor/bin/sail npm <command>./vendor/bin/sail testFollow these steps to set up the project on your local machine without Docker:
git clone https://github.com/prayangshu/laravel-user-management.git
cd laravel-user-management
composer install
npm install
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
npm run build
php artisan serve
Access the app at http://localhost:8000.
GET /register: Displays the registration form.POST /register: Handles the form submission and user creation.auth middleware. Handles session regeneration to prevent session fixation attacks.GET /login: Displays the login form.POST /login: Authenticates the user.POST /logout: Logs the user out and invalidates the session.GET /forgot-password: Displays the email input form.POST /forgot-password: Processes the request and sends the email.role column to the users table. Implements an AdminMiddleware to restrict access to administrative routes.admin applied to all /admin/* routes.GET /admin: Displays the admin dashboard.GET /admin/users: Lists all users.GET /admin/users/{user}/edit: Displays the user edit form.PUT /admin/users/{user}: Updates the user record.DELETE /admin/users/{user}: Removes the user from the database.GET /admin/password/change: Displays the password change form.PUT /admin/password/change: Handles the password update logic.<x-ui.card>, <x-ui.button>, <x-ui.input>, <x-ui.icon>) are used exclusively. [ HTTP Request ]
│
▼
+--------------------+
| Routes |
+--------------------+
│
▼
+--------------------+ +------------------+
| Controllers | ◄─── | Form Requests |
+--------------------+ +------------------+
│
│ (Calls)
▼
+--------------------+
| Services |
+--------------------+
│
│ (Uses)
▼
+--------------------+
| Models |
+--------------------+
│
│ (Queries)
▼
+--------------------+
| Database |
+--------------------+
... (Data returns up to Controller) ...
│
▼
+--------------------+
| Blade Views |
+--------------------+
│
▼
[ HTTP Response ]
This project prioritizes testing the Service Layer to ensure business logic is robust, independent of the HTTP layer, and free from side effects.
RefreshDatabase trait to ensure a clean state for every test.Mail) to prevent actual execution during tests.// tests/Unit/Services/AuthServiceTest.php
class AuthServiceTest extends TestCase
{
use RefreshDatabase;
public function test_it_registers_a_new_user()
{
// Arrange
$data = [
'name' => 'John Doe',
'email' => 'john@example.com',
'password' => 'secret123',
];
$service = new AuthService();
// Act
$user = $service->registerUser($data);
// Assert
$this->assertInstanceOf(User::class, $user);
$this->assertDatabaseHas('users', ['email' => 'john@example.com']);
$this->assertTrue(Hash::check('secret123', $user->password));
}
}
This application implements a multi-layered security strategy to protect user data and prevent common vulnerabilities.
auth middleware. Administrative routes are further secured by the admin middleware, ensuring strict role-based access control.guest middleware to prevent session confusion.Auth::user()->role === 'admin') before authorizing administrative actions, preventing horizontal and vertical privilege escalation.throttle middleware (5 attempts per minute for login, 3 for password reset) to mitigate brute-force attacks.This application is designed to scale horizontally and vertically with minimal refactoring. The following strategies outline the path from a single server to a high-traffic distributed system.
email, role) are indexed to maintain fast read performance as the dataset grows.read (SELECT) and write (INSERT/UPDATE/DELETE) operations. This allows distributing read traffic across multiple read replicas.file to redis or database to support horizontal scaling (multiple application servers sharing sessions).php artisan config:cache and php artisan route:cache in production to reduce boot time.sync.User::paginate()) to prevent memory exhaustion when retrieving large datasets.The application provides a RESTful API for external integrations. The API uses Laravel Sanctum for authentication and follows standard HTTP status codes.
All API requests (except login) require a Bearer Token in the Authorization header.
Header:
Authorization: Bearer <your-token>
Authenticates a user and returns an access token.
POST /api/login{
"email": "admin@example.com",
"password": "password"
}
{
"success": true,
"message": "Login successful.",
"data": {
"user": {
"id": 1,
"name": "Admin User",
"email": "admin@example.com",
"role": "admin",
"created_at": "2023-10-27T10:00:00+00:00",
"updated_at": "2023-10-27T10:00:00+00:00"
},
"token": "1|laravel_sanctum_token_string..."
}
}
Revokes the current access token.
POST /api/logout{
"success": true,
"message": "Logged out successfully.",
"data": null
}
Retrieves the authenticated user’s profile.
GET /api/user{
"success": true,
"message": "Success",
"data": {
"id": 1,
"name": "Admin User",
"email": "admin@example.com",
"role": "admin",
...
}
}
Retrieves a list of all registered users.
GET /api/admin/users{
"success": true,
"message": "Success",
"data": [
{
"id": 2,
"name": "John Doe",
"email": "john@example.com",
"role": "user",
...
},
...
]
}
Updates a user’s details.
PUT /api/admin/users/{id}{
"name": "Jane Doe",
"email": "jane@example.com",
"role": "user"
}
{
"success": true,
"message": "User updated successfully.",
"data": {
"id": 2,
"name": "Jane Doe",
...
}
}
Removes a user from the system.
DELETE /api/admin/users/{id}{
"success": true,
"message": "User deleted successfully.",
"data": null
}
This checklist outlines the essential steps to secure this application in a production environment.
production.false.php artisan key:generate..env is never committed to version control.chmod -R 775 storage bootstrap/cache).admin middleware.SESSION_SECURE_COOKIE=true in .env (requires HTTPS).SESSION_HTTP_ONLY=true.SESSION_SAME_SITE=lax or strict.Session::regenerate()).DROP or GRANT).email, role).ThrottleRequests middleware for all API endpoints.ForceHTTPS middleware or server config).composer audit regularly to check for PHP vulnerabilities.npm audit to check for frontend vulnerabilities.composer.lock and package-lock.json and review changes.X-Powered-By).This project has undergone a complete end-to-end audit to ensure it meets professional engineering standards.