Skip to content

amerhany/blog-task

Repository files navigation

Blog Task API

📑 Introduction

Blog Task is a simple blog application built with Laravel. This API allows users to manage posts and comments, including creating, updating, and retrieving data.


🛠️ Prerequisites

Make sure you have the following installed:

  • PHP 8.x
  • Composer
  • MySQL
  • Git

🚀 Installation Steps

  1. Clone the Repository
git clone https://github.com/amerhany/blog-task.git
cd blog-task
  1. Install Dependencies
composer install
  1. Environment Configuration
  • Copy the example environment file and modify it:
cp .env.example .env
  • Generate the application key:
php artisan key:generate
  • Update the following in the .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog_task
DB_USERNAME=root
DB_PASSWORD=your_password
  1. Generate JWT Secret

Run the following command to generate the JWT secret:

php artisan jwt:secret
  1. Database Setup
php artisan migrate
  • Seed the database with an admin user:
php artisan db:seed --class=AdminUserSeeder

🌐 Running the Server

php artisan serve

🧑‍💻 API Endpoints

Auth

  • Register: POST /api/auth/register
  • Login: POST /api/auth/login
  • Logout: POST /api/auth/logout (requires authentication)

Posts

  • List all posts: GET /api/posts
  • Search posts: GET /api/posts/search?query=title&category=1&start_date=2023-01-01&end_date=2023-12-31&author=5
  • Show specific post: GET /api/posts/{id}
  • Create post: POST /api/posts (requires authentication)
  • Update post: PUT /api/posts/{id} (requires authentication)
  • Delete post: DELETE /api/posts/{id} (requires authentication)

Comments

  • Add comment: POST /api/posts/{postId}/comments (requires authentication)
  • Update comment: PUT /api/posts/{postId}/comments/{id} (requires authentication)
  • Delete comment: DELETE /api/posts/{postId}/comments/{id} (requires authentication)

Testing the API

You can test the API using Postman or any other API testing tool. Make sure to include the Authorization: Bearer {token} header for authenticated routes.


🪲 Troubleshooting

  • If migrations fail, make sure the database credentials in the .env file are correct.
  • Check if your database server is running.

Feel free to open an issue if you encounter any problems!


You can directly paste this updated README content into your Canvas document to update it! Let me know if you need any further assistance.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages