This is a simple Laravel-based RESTful API for managing employee attendance. The API provides functionality for user registration, login, and CRUD operations on attendance records. The API also supports authentication using Laravel Sanctum and includes the ability to generate dummy data using Laravel's Faker library.
- User Registration: Allows users to register with a name, email, and password.
- User Login: Users can log in with email and password to obtain an authentication token.
- Attendance CRUD: Perform Create, Read, Update, and Delete operations on attendance records.
- Sanctum Authentication: Secure the API with Bearer Token authentication using Laravel Sanctum.
- Dummy Data Generation: The API includes functionality for generating dummy data (attendances and users) using Faker.
Follow these steps to set up the project locally:
First, clone the repository to your local machine:
git clone https://github.com/Joe1724/Laravel-Attendance-API
cd Laravel-Attendance-API'Make sure you have Composer installed. Then, install the project's dependencies by running:
composer installCreate a .env file by copying the .env.example file:
cp .env.example .envUpdate your .env file with your database credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=attendance_db
DB_USERNAME=root
DB_PASSWORD=Make sure to create the database (e.g., attendance_db) in MySQL or your preferred database system.
Run the following command to generate the application key:
php artisan key:generateRun the database migrations to set up the necessary tables:
php artisan migrateIf you want to seed the database with dummy data, use the following command:
php artisan db:seedThis will create users and attendance records using the factory and Faker.
Serve the Application
Now, you can serve the application using the built-in Laravel development server:
php artisan serveThe API will be accessible at http://127.0.0.1:8000.
Register a new user.
Request:
{
"name": "John Doe",
"email": "johndoe@example.com",
"password": "password123",
"password_confirmation": "password123"
}Response:
{
"message": "User registered successfully.",
"user": {
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com"
}
}Log in and receive an authentication token.
Request:
{
"email": "johndoe@example.com",
"password": "password123"
}Response:
{
"message": "Login successful.",
"access_token": "your-token-here"
}Get the authenticated user's details (requires authentication).
Response:
{
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com"
}Retrieve a list of all attendance records.
Response:
[
{
"id": 1,
"user_id": 1,
"attendance_date": "2024-12-01",
"status": "present"
},
...
]Create a new attendance record.
Request:
{
"attendance_date": "2024-12-02",
"status": "absent"
}Response:
{
"message": "Attendance created successfully.",
"attendance": {
"id": 2,
"user_id": 1,
"attendance_date": "2024-12-02",
"status": "absent"
}
}Update an existing attendance record.
Request:
{
"attendance_date": "2024-12-03",
"status": "late"
}Response:
{
"message": "Attendance updated successfully.",
"attendance": {
"id": 2,
"user_id": 1,
"attendance_date": "2024-12-03",
"status": "late"
}
}Delete an attendance record.
Response:
{
"message": "Attendance deleted successfully."
}If you would like to contribute to this project, feel free to fork the repository, create a new branch, and submit a pull request with your changes. Please make sure to follow the code style and write tests for any new features.
This project is open-source and available under the MIT License.
Let me know if you need further adjustments or additional details!