A clean and structured Laravel 10 RESTful API for managing tasks with authentication and task assignment.
- Laravel 10.0 with PHP 8.2.18
- Sanctum-based authentication (register, login, logout)
- Task CRUD operations
- Task assignment (admin can assign tasks to users)
- Filtering, sorting, and pagination of tasks
- Service-Repository pattern for business logic separation
- Resource collections for API responses
- Feature and unit tests
- PHP 8.2+
- Composer
- MySQL or other supported DB
Clone the repository and install dependencies:
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate
php artisan db:seed
Sanctum is used for token-based authentication.
- POST /api/register
- POST /api/login
- POST /api/logout (requires auth)
- GET /api/tasks
- POST /api/tasks
- GET /api/tasks/{id}
- PUT /api/tasks/{id}
- DELETE /api/tasks/{id}
- POST /api/tasks/{id}/assign (admin only)
- Task can be created by any user
- Only users with the role
admincan assign tasks
A default seeder adds:
- One admin user (admin@example.com, password: admin)
- Two regular users (ragib@example.com, password: ragib, hasnat@example.com, password: hasnat)
Feature and unit tests are written using Laravel's testing tools.
Run all tests:
php artisan test
Includes:
- Feature tests for API endpoints
- Unit tests for task assignment logic
This project follows the Service-Repository pattern:
- Repositories handle all DB queries
- Services handle business logic
- Resource Collections format API responses
Example structure:
app/
├── Http/Controllers
├── Http/Requests
├── Http/Resources
├── Models
├── Repositories
│ └── Interfaces
├── Services
- Role management is handled with a
rolecolumn in theuserstable (no separate roles table) user_idis automatically assigned as task creator during creation- Middleware protects all task routes via Sanctum