The Leave Management System allows employees to apply for leaves and administrators to approve or reject them. The system includes:
-
Employee Features:
- Apply for different types of leaves (Sick, Casual, Emergency, Annual, Maternity, Paternity)
- View leave application history
- Edit pending applications
-
Admin Features:
- View all leave applications
- Approve or reject applications
- Add comments to decisions
- Manage leave records
First, ensure your database is configured in .env, then run:
php artisan migrateThis will create the leaves table with the following structure:
id- Primary keyuser_id- Foreign key to users tableemployee_name- Employee nameleave_type- Type of leave (enum)from_date- Start dateto_date- End datedays_hours- Number of days/hoursday_type- Full Day, Half Day, or Hoursreason- Reason for leavestatus- Applied, Approved, or Rejectedapproved_by- Admin who approved/rejectedapproved_at- Timestamp of approvaladmin_comments- Admin commentscreated_at/updated_at- Laravel timestamps
- Access the Leave Management system from the sidebar: Leave
- The route is:
/superadmin/leaves
- Click "Apply Leave" button
- Fill in the form:
- Select Employee
- Choose Leave Type
- Set From and To dates (system auto-calculates days)
- Enter Days/Hours
- Select Day Type
- Provide reason
- Submit the application
- View all applications in the main table
- For "Applied" status leaves:
- Click Approve (green button) or Reject (red button)
- Add optional comments
- Submit decision
- Applied (Yellow badge) - Pending approval
- Approved (Green badge) - Approved by admin
- Rejected (Red badge) - Rejected by admin
The following routes are available:
GET /superadmin/leaves- View all leaves (index)POST /superadmin/leaves- Create new leave applicationPUT /superadmin/leaves/{leave}- Update leave applicationPUT /superadmin/leaves/{leave}/approve- Approve/reject leaveDELETE /superadmin/leaves/{leave}- Delete leave application
app/Http/Controllers/SuperAdmin/LeaveController.php
app/Models/Leave.php
resources/views/superadmin/leaves/leave.blade.php
routes/superadmin.php(lines around 339-347)
database/migrations/YYYY_MM_DD_HHMMSS_create_leaves_table.php
-
Start the server:
php artisan serve
-
Access the application:
- Navigate to your admin panel
- Go to the "Leave" section from the sidebar
-
Test workflow:
- Apply for a leave (ensure users exist in database)
- View the application in the table
- Approve/reject as admin
- Verify status changes
If you need to test with sample data, you can manually insert users and leaves into the database:
-- Insert sample users (if not existing)
INSERT INTO users (name, email, password, created_at, updated_at) VALUES
('John Doe', 'john@example.com', '$2y$10$hash', NOW(), NOW()),
('Jane Smith', 'jane@example.com', '$2y$10$hash', NOW(), NOW());
-- Insert sample leaves
INSERT INTO leaves (user_id, employee_name, leave_type, from_date, to_date, days_hours, reason, status, created_at, updated_at) VALUES
(1, 'John Doe', 'Sick Leave', '2024-12-24', '2024-12-24', 1, 'Fever and cold', 'Approved', '2024-12-23 10:00:00', '2024-12-23 14:30:00'),
(2, 'Jane Smith', 'Casual Leave', '2024-12-10', '2024-12-10', 1, 'Personal work', 'Applied', '2024-12-09 09:15:00', '2024-12-09 09:15:00');The system includes JavaScript for:
- Auto-calculating days between from and to dates
- Modal handling for approve/reject actions
- Form validation and user experience enhancements
-
Database Connection Issues:
- Check
.envfile database configuration - Ensure MySQL/database server is running
- Check
-
Route Not Found:
- Clear route cache:
php artisan route:clear - Check if route is properly defined in
routes/superadmin.php
- Clear route cache:
-
View Not Found:
- Ensure view file exists at correct path
- Check case sensitivity in file names
-
Permission Issues:
- Ensure proper middleware is applied to routes
- Check user authentication and permissions
Potential improvements to consider:
- Leave balance tracking per employee
- Leave calendar view
- Email notifications for applications and approvals
- Leave types configuration from admin panel
- Reporting and analytics
- Employee self-service portal
- Leave policy configuration
- Integration with HR systems
The leave management system is now fully functional and ready to use!