A modern Laravel-based blog application with RESTful API architecture, featuring user authentication, post management, and image handling capabilities. This repository contains a complete RESTful API for a blogging system that manages users, posts, images, and content publishing workflows. The project demonstrates clean code design, repository pattern implementation, API documentation, and modern Laravel development practices.
This project showcases modern backend development expertise, with a focus on designing and implementing robust, scalable, and maintainable blog APIs. Laravel is a highly popular framework widely adopted in production environments. It offers numerous built-in features that simplify handling a variety of use cases. The project implements advanced features like SEO optimization, content publishing workflows, and comprehensive API documentation.
- Language: PHP
8.2 - Framework: Laravel
12.x - Database: SQLite (development) / MySQL/PostgreSQL (production)
- Authentication: Laravel Sanctum
- Documentation: L5-Swagger
- Testing: PHPUnit
I use the Repository Design Pattern in this project. The Repository Design Pattern in Laravel is utilized to separate data access logic from the business logic of the application. This approach offers benefits such as more structured code, easier testing, and flexibility to accommodate changes. By using a repository, you can replace or modify the data source (e.g., switching from a database to an external API) without altering the business logic in controllers or services. Additionally, this pattern facilitates the implementation of SOLID principles, particularly the Dependency Inversion Principle, as controllers or services depend only on contracts (interfaces) rather than direct implementations.
- PHP >= 8.2
- Composer
- SQLite (for development)
-
Clone the repository:
git clone <repository-url> simple-blog-api
-
Navigate to the project directory:
cd simple-blog-api -
Install PHP dependencies:
composer install
-
Set up the environment file:
cp .env.example .env
Configure the database and other environment variables as needed.
-
Generate app key for encryption:
php artisan key:generate
-
Set up the database:
touch database/database.sqlite php artisan migrate --seed
-
Create storage symlink:
php artisan storage:link
-
Generate API documentation:
php artisan l5-swagger:generate
To start the project locally, use the following command:
# Start the Laravel server
php artisan serve
# Or run with queue worker
php artisan serve &
php artisan queue:workThe API documentation is available via Swagger. Once the project is running, visit the following URL to explore the endpoints:
http://localhost:8000/api/documentation
POST /api/v1/auth/register- User registrationPOST /api/v1/auth/login- User loginGET /api/v1/auth/me- Get current user (protected)DELETE /api/v1/auth/logout- Logout (protected)
GET /api/v1/posts/published- Get all published postsGET /api/v1/posts/{slugOrId}/public- Get single published post
GET /api/v1/posts- List user's postsPOST /api/v1/posts- Create new postGET /api/v1/posts/{id}- Get specific postPUT /api/v1/posts/{id}- Update postDELETE /api/v1/posts/{id}- Delete postPOST /api/v1/posts/{id}/publish- Publish postPOST /api/v1/posts/{id}/unpublish- Unpublish post
GET /api/v1/users- List usersGET /api/v1/users/{userId}/posts- Get posts by user
POST /api/v1/images/upload- Upload imageDELETE /api/v1/images/delete- Delete image
Unit and feature tests are implemented using PHPUnit to ensure the reliability of the API. Run tests using:
Before running tests, ensure you have a dedicated testing database configured. This prevents your development data from being affected during testing.
# Run all tests
composer test
# Run with coverage
php artisan test --coverageThe project follows Laravel's conventional structure with additional repository pattern implementation:
app/
├── Http/Controllers/ # API Controllers
├── Models/ # Eloquent Models
├── Repositories/ # Repository Pattern Implementation
├── Interfaces/ # Repository Interfaces
└── Helpers/ # Helper Classes
database/
├── migrations/ # Database Migrations
├── seeders/ # Database Seeders
└── factories/ # Model Factories
routes/
└── api.php # API Routes
storage/
└── api-docs/ # Generated API Documentation
This project implements the Repository Pattern for better code organization and testability:
AuthRepository- User authentication logicPostRepository- Post management operationsUserRepository- User-related operations
- Standard Laravel user fields
- Email verification support
- Title, content, excerpt
- SEO fields (meta_title, meta_description, meta_keywords)
- Publishing workflow (status, is_published, published_at)
- Categorization (category_code, tags)
- Reading time calculation
- Featured image support
Key environment variables to configure:
APP_NAME="Simple Blog App"
APP_URL=http://localhost:8000
DB_CONNECTION=sqlite
DB_DATABASE=/path/to/database.sqlite
SANCTUM_STATEFUL_DOMAINS=localhost:3000- User Authentication: Registration, login, logout with Laravel Sanctum
- Post Management: Create, read, update, delete blog posts
- Content Publishing: Draft and publish workflow for posts
- Image Upload: Support for featured images and content images
- SEO Optimization: Meta titles, descriptions, and keywords
- Search & Filtering: Posts by category, tags, and search terms
- Reading Time: Automatic calculation based on content length
- API Documentation: Swagger/OpenAPI documentation with L5-Swagger
I would greatly appreciate any feedback on my work, as it will help me improve and grow as a developer. If you have any comments, suggestions, or questions regarding this project, please feel free to reach out:
- Name: Abel A Simanungkalit
- Email: work.abelardhana@gmail.com
- GitHub Profile: https://github.com/abela-a
Thank you for taking the time to review this project!