This project is a Laravel-based backend API for HR management. It implements employee and position management, authentication, notifications, hierarchical queries, logging, data import/export, rate limiting, and more, strictly following the assignment requirements.
- Employee and position CRUD
- Authentication (Sanctum)
- Notifications (email, broadcast)
- Hierarchical queries
- Logging (DB and file)
- Data import/export (CSV, JSON, SQL)
- Rate limiting (10 requests/min per user)
- Custom Artisan commands
app/
├── Http/
│ └── Controllers/ # Controllers: Handle HTTP requests and responses for API endpoints
├── Actions/ # Actions: Business logic for CRUD/search, called by controllers
├── Repositories/ # Repositories: Data access, Eloquent queries
├── Services/ # Services: Reusable business logic/orchestration (where used)
├── Observers/ # Observers: Listen for model events, trigger logging/notifications/history
├── Notifications/ # Notifications: Email/broadcast for salary changes, new employee
├── Console/
│ └── Commands/ # Commands: Custom Artisan CLI commands (export, cleanup, bulk ops)
├── Traits/ # Traits: Shared code, e.g., ApiResponse.php for standardized responses
- PHP: ^8.2
- Composer: Latest version recommended
- Database: MariaDB/MySQL (recommended), other Laravel-supported DBs possible
- Node.js & npm: For broadcasting/queues (if needed)
- Required Composer Packages:
laravel/framework^12.0laravel/sanctum^4.0laravel/tinkerifsnop/mysqldump-php- See
composer.jsonfor full list
- Clone the Repository
git clone https://github.com/Muhamad-jamal/Assignment.git cd Assignment - Install Dependencies
composer install
- Environment Setup
- Copy the example environment file and configure your DB credentials:
cp .env.example .env
- Edit
.envfor your database settings:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=assignment DB_USERNAME=root DB_PASSWORD=your_password - Email Setup:
Configure the following mail settings in your
.envfile to enable email notifications (salary change, manager notification, etc.):(You may use Mailtrap or any SMTP provider for testing.)MAIL_MAILER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=your_mailtrap_username MAIL_PASSWORD=your_mailtrap_password MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=hr@example.com MAIL_FROM_NAME="HR Management"
- Copy the example environment file and configure your DB credentials:
- Generate Application Key
php artisan key:generate
- Run Migrations and Seeders
This will automatically:
php artisan migrate --seed
- Create an admin user:
- Email: admin@example.com
- Password: password
- Use factories to create:
- 5 positions
- 5 employees
You can customize the seed data in
database/seedersand factories indatabase/factories.
- Create an admin user:
- Start the Development Server
php artisan serve
- Run the Queue Worker
To process email and broadcast notifications, start the queue worker in a separate terminal:
(This is required for notifications to be sent and broadcasted.)
php artisan queue:work
POST /api/v1/auth/register– Register new userPOST /api/v1/auth/login– Login, receive tokenPOST /api/v1/auth/logout– Logout, invalidate token
GET /api/v1/employees– List all employeesGET /api/v1/employees/search?name=alice&salary=5000– Search employeesGET /api/v1/employees/without-recent-salary-change?months=12– Employees without salary changePOST /api/v1/employees– Create new employeeGET /api/v1/employees/{id}– Show employee detailsPATCH /api/v1/employees/{id}– Update employee info/salaryDELETE /api/v1/employees/{id}– Delete employeeGET /api/v1/employees/{id}/hierarchy/names– Get hierarchy namesGET /api/v1/employees/{id}/hierarchy/names-salaries– Get hierarchy names and salariesGET /api/v1/employees/export/csv– Export employees as CSVPOST /api/v1/employees/import/csv– Import employees from CSV
GET /api/v1/positions– List all positionsGET /api/v1/positions/{id}– Show position detailsPOST /api/v1/positions– Create positionPATCH /api/v1/positions/{id}– Update positionDELETE /api/v1/positions/{id}– Delete position
php artisan employee-logs:cleanup– Delete employee logs older than one month from the logs tablephp artisan logs:remove-all– Remove all log files from storage/logs directoryphp artisan employees:insert {count}– Insert a given number of employees with a progress barphp artisan db:export– Export the entire database to a SQL file in storage/backupsphp artisan employees:export-json– Export all employee data to a JSON file in storage/backups
A Postman collection is provided in the project root as Assignment.postman_collection.json.
Instructions for Reviewers:
- Import
Assignment.postman_collection.jsoninto Postman. - Update environment variables in Postman as needed (e.g., base URL).
- Refer to the API Reference above for details on each endpoint.
MIT