Skip to content

developermithu/api-blog-laravel

Repository files navigation

Laravel - Inertia - React

A Laravel-based RESTful API for managing blog posts and categories.

Features

  • 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

Frontend Repository

Installation Steps

  1. Clone the repository:
git clone https://github.com/developermithu/api-blog-laravel.git
  1. Change directory:
cd api-blog-laravel
  1. Install dependencies:
composer install
  1. Copy the .env.example file to .env:
cp .env.example .env
  1. Generate the application key:
php artisan key:generate
  1. 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=
  1. Migrate and seed the database:
php artisan migrate:fresh --seed
  1. Start the development server:
php artisan serve 
  1. Open the application in your web browser at http://localhost:8000.

API Documentation

Authentication

All authentication endpoints are prefixed with /api/auth.

Register

POST /api/auth/register
Parameter Type Description
name string Required. User's name
email string Required. User's email
password string Required. User's password

Login

POST /api/auth/login
Parameter Type Description
email string Required. User's email
password string Required. User's password

Successful login returns a Bearer token that should be used for authenticated requests.

Logout

POST /api/auth/logout

Requires authentication. Invalidates the current access token.

Posts

Get All Posts

GET /api/posts

Supports filtering by:

GET /api/posts?search=query&status=draft&is_featured=true&filter=trash&page=1&per_page=6
  • search query [search=query]
  • status [status=draft/published]
  • featured posts [is_featured=true/false]
  • trashed posts [filter=all/trash/with_trashed]

Get Single Post

GET /api/posts/{slug}

Create Post (Admin Only)

POST /api/posts
Parameter Type Description
title string Required. Post title
slug string Required. Post slug
excerpt string Required. Post excerpt
content string Required. Post content
category_id integer Required. Category ID
status string Required. Post status (draft/published)
is_featured boolean Optional. Featured post status
cover_image file Optional. Post image

Update Post (Admin Only)

PUT /api/posts/{slug}

Accepts the same parameters as the create endpoint.

Delete Post (Admin Only)

DELETE /api/posts/{slug}

Soft deletes the post. The post can be restored later.

Restore Post (Admin Only)

POST /api/posts/{id}/restore

Restores a soft-deleted post.

Force Delete Post (Admin Only)

DELETE /api/posts/{id}/force-delete

Permanently deletes the post.

Categories

Get All Categories

GET /api/categories

Get Single Category

GET /api/categories/{category}

Create Category (Admin Only)

POST /api/categories
Parameter Type Description
name string Required. Category name
slug string Required. Category slug

Update Category (Admin Only)

PUT /api/categories/{category}

Delete Category (Admin Only)

DELETE /api/categories/{category}

Authentication

All admin-only endpoints require authentication using a Bearer token. Include the token in the Authorization header:

Authorization: Bearer <your_token>

Error Responses

The API uses standard HTTP status codes to indicate the success or failure of requests:

  • 200 OK - Request succeeded
  • 201 Created - Resource created successfully
  • 400 Bad Request - Invalid request parameters
  • 401 Unauthorized - Missing or invalid authentication token
  • 403 Forbidden - Authenticated but not authorized to access the resource
  • 404 Not Found - Resource not found
  • 422 Unprocessable Entity - Validation errors

Made with ❤️ by developermithu

About

Blog backend - Laravel 12, Inertia v2, React 19

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy