Skip to content

aamilham/backend-employee-management

Repository files navigation

Employee Management System - Backend

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

Authors

Features

  • 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

prerequisites to install:

Installation Steps

1. Clone the Repository

Clone the repository to your local

2. Install Dependencies

Install the PHP dependencies using Composer:

composer install

3. Set Up Environment Variables

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

4. Create the Database

Create a new MySQL database for the project:

CREATE DATABASE your_database_name;

5. Run Migrations

Run the database migrations to set up the database schema:

php artisan migrate

6. Seed the Database (Optional)

If you have seeders to populate the database with initial data, run:

php artisan db:seed

7. Start the Development Server

Start the Laravel development server:

php artisan serve

The backend should now be running at http://localhost:8000.

8. API Endpoints

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)

9. Add Ons - Deploying to Production

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.

10. Troubleshooting

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.

About

Backend side of Employee Management Fullstack Web Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published