Employee Management System backend built using Laravel. This backend provides RESTful API to manage employee data, supports CRUD (Create, Read, Update, Delete) operations, along with authentication and authorization features using JWT. Frontend Repository
- User Authentication and Registration: Users can register and log in to gain access to the API.
- Employee Management: Supports creating, reading, updating, and deleting employee data.
- JWT-Based Authentication: Uses JSON Web Token to secure protected endpoints.
- Role-Based Access Control: Includes a superadmin role for special access to certain endpoints.
prerequisites to install:
Clone the repository to your local
Install the PHP dependencies using Composer:
composer install
Copy the example environment file and configure your environment variables:
cp .env.example .env
Open the .env
file and update the following settings to match your environment:
-
Database Configuration:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_database_user DB_PASSWORD=your_database_password
-
JWT Secret:
JWT_SECRET=your_generated_jwt_secret
Generate the JWT secret if not done already:
php artisan jwt:secret
Create a new MySQL database for the project:
CREATE DATABASE your_database_name;
Run the database migrations to set up the database schema:
php artisan migrate
If you have seeders to populate the database with initial data, run:
php artisan db:seed
Start the Laravel development server:
php artisan serve
The backend should now be running at http://localhost:8000
.
You can test the API endpoints using tools like Postman or cURL. Below are some example routes:
- User Registration:
POST /api/register
- User Login:
POST /api/login
- Get All Employees:
GET /api/employees
(Requires authentication) - Create New Employee:
POST /api/employees
(Requires authentication) - Update Employee:
PUT /api/employees/{id}
(Requires authentication) - Delete Employee:
DELETE /api/employees/{id}
(Requires authentication) - User Logout:
POST /api/logout
(Requires authentication) - User self-identification:
POST /api/me
(Requires authentication) - Get Employees Sorted by Salary:
GET /api/employees-by-salary
(Requires authentication and superadmin role)
For production deployment, ensure you:
- Set the appropriate environment variables in your
.env
file. - Use a production server with a proper web server configuration (e.g., Apache or Nginx).
- Consider using a process manager like Supervisor to keep the application running.
- Set up HTTPS for secure connections.
If you encounter any issues during the installation:
- Check the logs in
storage/logs/laravel.log
. - Ensure the
.env
file is configured correctly. - Verify that all services (e.g., MySQL, PHP) are running.