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.
Make sure you have the following installed:
- PHP 8.x
- Composer
- MySQL
- Git
- Clone the Repository
git clone https://github.com/amerhany/blog-task.git
cd blog-task
- Install Dependencies
composer install
- 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
- Generate JWT Secret
Run the following command to generate the JWT secret:
php artisan jwt:secret
- Database Setup
php artisan migrate
- Seed the database with an admin user:
php artisan db:seed --class=AdminUserSeeder
php artisan serve
- Access the API at: http://127.0.0.1:8000
- Register: POST
/api/auth/register
- Login: POST
/api/auth/login
- Logout: POST
/api/auth/logout
(requires authentication)
- 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)
- 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)
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.
- 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.