A robust RESTful API for managing company expenses, built with Laravel 12.
- Multi-tenancy: Each company has its own isolated data environment
- Role-based Access Control: Admin, Manager, and Employee roles with different permissions
- Expense Management: Create, read, update, and delete expense records
- User Management: Admin can manage users within their company
- Audit Logging: Track all changes to expenses for accountability
- Caching: Improved performance with database caching
- Weekly Reports: Automated expense reports sent to company admins
- API Authentication: Secure token-based authentication with Laravel Sanctum
- PHP 8.2+
- MySQL 8.0+
- Composer
-
Clone the repository:
cd expense-management-api -
Install dependencies:
composer install -
Create and configure your environment file:
cp .env.example .env -
Configure your database in the
.envfile:DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=expense_management DB_USERNAME=root DB_PASSWORD= -
Generate application key:
php artisan key:generate -
Run migrations and seed the database:
php artisan migrate --seed -
Start the development server:
php artisan serve
POST /api/register- Register a new company and adminPOST /api/login- Login and get authentication tokenPOST /api/logout- Logout and invalidate token
GET /api/users- List all users (Admin only)GET /api/users/{id}- Get user details (Admin only)POST /api/users- Create new user (Admin only)PUT /api/users/{id}- Update user (Admin only)DELETE /api/users/{id}- Delete user (Admin only)
GET /api/expenses- List all expensesGET /api/expenses/{id}- Get expense detailsPOST /api/expenses- Create new expensePUT /api/expenses/{id}- Update expense (Admin/Manager only)DELETE /api/expenses/{id}- Delete expense (Admin only)
Use Postman or any API client to test the endpoints. Sample requests are included in the documentation.
The application includes a scheduled task to send weekly expense reports to company admins every Monday at 8:00 AM.
To test this functionality manually, run:
php artisan expenses:send-weekly-report
php artisan queue:work
This API implements:
- Token-based authentication
- Role-based access control
- Cross-company data isolation
- Input validation
- Audit logging