Introduction
Welcome to the Blog API. All responses are returned in JSON format. Authentication is handled via Laravel Sanctum Bearer tokens.
Database Seeded Accounts
After running php artisan
migrate --seed,
you can use these pre-defined accounts to test the API permissions and features.
Email: admin@example.com
Pass: password
Email: user@example.com
Pass: password
Base URL
https://blog.yuldoshew.uz/api
Standard Response Format
Used by BaseController
{
"status": "success",
"status_code": 200,
"message": "Operation successful.",
"data": { ... },
"error_note": null
}
Register User
/register
Creates a new user account and returns an access token.
Body Parameters
| name* | string | User's full name. Max 255 chars. |
| email* | string | Must be a valid email and unique in database. |
| password* | string | Min 8 chars. Must be confirmed. |
| password_confirmation* | string | Must match the password field exactly. |
{
"status": "success",
"status_code": 201,
"message": "User registered successfully. Please verify your email.",
"data": {
"user": {
"name": "John Doe",
"email": "john@example.com",
"role": "user",
"id": 1
},
"token": "1|AbCdEf..."
},
"error_note": null
}
{
"status": "error",
"status_code": 400,
"error_message": "Registration failed.",
"error_note": "Validation error or database issue."
}
Login
/login
Authenticate user and create a new API token.
Body Parameters
| email* | string | Valid user email. |
| password* | string | User password. |
{
"status": "success",
"status_code": 200,
"message": "User logged in successfully.",
"data": {
"user": { "id": 1, "name": "John" },
"token": "2|Zxy..."
}
}
{
"status": "error",
"status_code": 401,
"error_message": "Unauthorized.",
"errors": {
"email": "Invalid credentials."
},
"error_note": "Credentials mismatch."
}
Current User
/user
Retrieve the authenticated user's profile information.
{
"status": "success",
"status_code": 200,
"message": "User profile retrieved.",
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "user",
"created_at": "2024-01-01..."
}
}
Resend Verification
/email/verification-notification
Sends a new email verification link to the authenticated user. If the email is already verified, it returns a 400 error.
Body Parameters
No parameters required. The user is identified via the Bearer Token.
{
"status": "success",
"status_code": 200,
"message": "Verification link sent.",
"data": null,
"error_note": null
}
{
"status": "error",
"status_code": 400,
"error_message": "Already verified.",
"error_note": "Email already verified."
}
Verify Email
/email/verify/{id}/{hash}
Validates the user's email address using the ID and hash provided in the verification link.
URL Parameters
| id* | integer | The unique ID of the user. |
| hash* | string | The verification hash sent to the user's email. |
{
"status": "success",
"status_code": 200,
"message": "Email verified successfully.",
"data": null
}
{
"status": "success",
"status_code": 200,
"message": "Email already verified.",
"data": null
}
Forgot Password
/forgot-password
Sends a password reset link to the user's email address if it exists in our system.
Body Parameters
| email* | string | Registered user email address. Must be a valid email. |
{
"status": "success",
"status_code": 200,
"message": "Reset link sent to your email.",
"data": null,
"error_note": null
}
{
"status": "error",
"status_code": 400,
"error_message": "Failed.",
"error_note": "Email not found or error occurred."
}
Reset Password
/reset-password
Updates the user's password using the token received via email.
Body Parameters
| token* | string | The reset token received in the email. |
| email* | string | User's email address. |
| password* | string | New password. Min 8 chars, must be confirmed. |
| password_confirmation* | string | Must match the password field. |
{
"status": "success",
"status_code": 200,
"message": "Password reset successfully.",
"data": null
}
{
"status": "error",
"status_code": 400,
"error_message": "Reset failed.",
"error_note": "Invalid token or email."
}
Update Password
/user/password-update
Body Parameters
| current_password* | string | Must match the user's current password. |
| password* | string | New password. Min 8 chars. |
| password_confirmation* | string | Must confirm new password. |
{
"status": "success",
"status_code": 200,
"message": "Password updated successfully.",
"data": null
}
{
"message": "The current password is incorrect.",
"errors": {
"current_password": [
"The current password is incorrect."
]
}
}
Logout
/logout
Revokes the current access token. User must login again to access protected resources.
{
"status": "success",
"status_code": 200,
"message": "Logged out successfully.",
"data": null
}
Delete Account
/user/delete
Permanently deletes the user record and all associated data/tokens. This action cannot be undone.
{
"status": "success",
"status_code": 200,
"message": "Account deleted successfully.",
"data": null
}
Users List
/users-list
Retrieves a paginated list of all registered users.
Requires admin middleware. Standard users will receive a
403 Forbidden response.
{
"status": "success",
"status_code": 200,
"message": "Users list retrieved.",
"data": [
{ "id": 1, "name": "Admin", "role": "admin" },
{ "id": 2, "name": "User", "role": "user" }
],
"links": { ... },
"meta": { ... }
}
List Categories
/categories
Fetch all categories. This is a public endpoint used for navigation or filtering posts.
{
"status": "success",
"status_code": 200,
"message": "Categories retrieved successfully.",
"data": [
{ "id": 1, "name": "Tech", "slug": "tech" },
{ "id": 2, "name": "Design", "slug": "design" }
]
}
Single Category
/categories/{id}
Retrieve detailed information about a specific category by its ID.
Path Parameters
| id* | integer | The unique identifier of the category. |
{
"status": "success",
"status_code": 200,
"message": "Category details.",
"data": {
"id": 1,
"name": "Tech",
"slug": "tech"
}
}
Create Category
/categories
Body Parameters
| name* | string | The name of the category. Must be unique. |
{
"status": "success",
"status_code": 201,
"message": "Category created successfully.",
"data": { "id": 3, "name": "AI" }
}
{
"status": "error",
"status_code": 403,
"error_message": "Access Denied."
}
Update Category
/categories/{id}
Body Parameters
| name* | string | New category name. |
{
"status": "success",
"status_code": 200,
"message": "Category updated.",
"data": { "id": 1, "name": "Updated Tech" }
}
Delete Category
/categories/{id}
Permanently deletes the category.
{
"status": "success",
"status_code": 200,
"message": "Category deleted successfully.",
"data": null
}
List Posts
/posts
Returns only **published** posts with pagination. Includes user, category info, and like counts.
Query Parameters
| per_page | int | Results per page (Default: 10). |
| search | string | Search in title or body content. |
| category_id | int | Filter posts by a specific category. |
{
"status": "success",
"data": {
"current_page": 1,
"data": [
{
"id": 1,
"title": "Post Title",
"likes_count": 5,
"user": { "id": 1, "name": "Admin" },
"category": { "id": 1, "name": "Tech" }
}
]
}
}
Admin All Posts
/posts_all
Administrative endpoint to view all posts, including **drafts**. Supports the same filters as the public index.
Single Post Details
/posts/{id}
Retrieves full details of a specific post. Accessing this endpoint
automatically increments the views_count field.
Path Parameters
| id* | integer/slug | The unique ID of the post to retrieve. |
Includes (Relationships)
This endpoint automatically returns the following nested objects:
- user: The author's basic profile.
- category: The category the post belongs to.
- comments: All comments associated with this post.
{
"status": "success",
"message": "Post details retrieved.",
"data": {
"id": 1,
"title": "Mastering Laravel APIs",
"body": "Full post content here...",
"views_count": 154,
"user": { "id": 1, "name": "Admin" },
"category": { "id": 2, "name": "Backend" },
"comments": [...]
}
}
{
"status": "error",
"message": "Post not found!"
}
Create Post
/posts
Request Body (Multipart/Form-Data)
| category_id* | int | Must exist in categories table. |
| title* | string | Maximum 255 characters. |
| body* | text | The main content of the post. |
| image | file | JPG, JPEG, PNG (Max: 4MB). |
| status | string | Choices: draft, published. |
{
"status": "success",
"status_code": 201,
"data": {
"id": 10,
"title": "How to use Laravel",
"image": "posts/filename.jpg",
"user_id": 1
}
}
Update Post
/posts/{id}
Updates post details and automatically generates a new slug if the title is changed. Replaces existing image if a new one is provided.
Pro-Tip: PHP/Laravel sometimes struggles with
multipart/form-data on PUT requests. Use POST and add _method:
PUT to your body fields.
{
"status": "success",
"message": "Post updated successfully.",
"data": { "slug": "new-generated-slug" }
}
Delete Post
/posts/{id}
Deletes post and permanently removes the associated image file from disk.
{
"status": "success",
"message": "Post deleted successfully.",
"data": []
}
Post Comment
/posts/{postId}/comments
Body Parameters
| body* | string | The content of the comment. |
{
"status": "success",
"message": "Comment added.",
"data": { "id": 5, "body": "Hello world" }
}
Edit Comment
/comments/{comment}
Updates the body of an existing comment. Requires the user to be the original author.
Body Parameters
| body* | string | Updated content. |
Delete Comment
/comments/{comment}
Permanently removes the comment. Authorized for owners and administrators.
{
"status": "success",
"message": "Comment deleted."
}
Toggle Like
/posts/{post}/like
This is a dynamic endpoint. If the user has not liked the post, it will create a "Like". If they have already liked it, the "Like" will be removed (Unlike).
Path Parameters
| post* | integer | The unique ID of the post. |
{
"status": "success",
"message": "Post liked.",
"data": { "liked": true }
}
{
"status": "success",
"message": "Post unliked.",
"data": { "liked": false }
}
My Favorites
/my-favorites
Returns a paginated list of posts that the currently authenticated user has liked.
{
"status": "success",
"data": [
{
"id": 12,
"title": "A post I liked earlier",
"created_at": "2024-06-01"
}
]
}
List Comments
/posts/{postId}/commentsFetch all comments associated with a specific post. Usually includes user profiles for display.
Path Parameters
{ "status": "success", "data": [ { "id": 1, "body": "Great post! Thanks for sharing.", "user": { "name": "John Doe" }, "created_at": "2024-05-20..." } ] }