A Laravel-based RESTful API for managing blog posts and categories.
- Authentication with Laravel Sanctum
- Post management (CRUD operations)
- Category management
- Role-based access control (Admin/User)
- Soft deletes for posts
- Media uploads for post images
- Clone the repository:
git clone https://github.com/developermithu/api-blog-laravel.git
- Change directory:
cd api-blog-laravel
- Install dependencies:
composer install
- Copy the
.env.example
file to.env
:
cp .env.example .env
- Generate the application key:
php artisan key:generate
- Update the database configuration in the
.env
file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=api-blog-laravel
DB_USERNAME=root
DB_PASSWORD=
- Migrate and seed the database:
php artisan migrate:fresh --seed
- Start the development server:
php artisan serve
- Open the application in your web browser at
http://localhost:8000
.
POST /api/register
Parameter | Type | Description |
---|---|---|
name |
string |
Required. User's name |
email |
string |
Required. User's email |
password |
string |
Required. User's password |
POST /api/login
Parameter | Type | Description |
---|---|---|
email |
string |
Required. User's email |
password |
string |
Required. User's password |
GET /api/posts
GET /api/posts/{id}
POST /api/posts
Parameter | Type | Description |
---|---|---|
title |
string |
Required. Post title |
slug |
string |
Required. Post slug |
content |
string |
Required. Post content |
category_id |
integer |
Required. Category ID |
status |
string |
Required. Post status (draft/published) |
cover image |
file |
Optional. Post image |
PUT /api/posts/{slug}
DELETE /api/posts/{slug}
GET /api/categories
GET /api/categories/{id}
POST /api/categories
Parameter | Type | Description |
---|---|---|
name |
string |
Required. Category name |
slug |
string |
Required. Category slug |
PUT /api/categories/{id}
DELETE /api/categories/{id}
All admin-only endpoints require authentication using a Bearer token. Include the token in the Authorization header:
Authorization: Bearer <your_token>