Skip to main content

Endpoint

DELETE /articles/{id}
This endpoint requires authentication with a valid JWT token AND Admin role.

Description

Deletes a specific article by ID, including all associated images. The article is soft-deleted, meaning it’s marked as deleted but remains in the database for potential recovery. The endpoint:
  • Validates that the article exists
  • Deletes all associated images from storage and database
  • Soft-deletes the article record
  • Uses database transactions to ensure atomicity
This endpoint performs a soft delete. The article is marked as deleted but can be recovered by database administrators if needed. All image files are permanently deleted from storage.

Authentication

Authorization
string
required
Bearer token for authentication. Format: Bearer YOUR_JWT_TOKEN
User must have the Admin role. Regular users will receive a 403 Forbidden response.

Headers

Accept-Language
string
default:"en"
Language preference for response messages. Supported values: en, es
Accept
string
default:"application/json"
Response content type

Path Parameters

id
integer
required
The unique ID of the article to delete

Response

Success Response (200 OK)

success
boolean
required
Always true for successful deletions
message
string
required
Success message indicating the article was deleted
data
null
No data is returned for delete operations

Example Request

curl -X DELETE https://api.example.com/articles/1 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Accept: application/json" \
  -H "Accept-Language: en"

Example Response

Success (200 OK)

{
  "success": true,
  "message": "Article deleted successfully",
  "data": null
}

Error Responses

401 - Unauthorized

Returned when no authentication token is provided or the token is invalid.
{
  "success": false,
  "message": "Unauthenticated",
  "errors": null
}

403 - Forbidden (Not Admin)

Returned when the authenticated user doesn’t have the Admin role.
{
  "success": false,
  "message": "Forbidden. Admin role required",
  "errors": null
}

400 - Bad Request (Article Not Found)

Returned when trying to delete an article that doesn’t exist or has already been deleted.
{
  "success": false,
  "message": "Article not found",
  "errors": null
}

500 - Internal Server Error

Returned when the deletion fails due to a server error (e.g., database transaction failure, file system error).
{
  "success": false,
  "message": "Article deletion failed",
  "errors": {
    "exception": "Unable to delete image files from storage"
  }
}

Deletion Process

The deletion follows this sequence:
  1. Validation: Check if the article exists
  2. Transaction Start: Begin database transaction
  3. Image Deletion:
    • Delete all image files from storage
    • Remove all image records from database
  4. Article Deletion: Soft-delete the article record
  5. Transaction Commit: Commit if all steps succeed
  6. Rollback: If any step fails, all changes are rolled back

Implementation Notes

  • Uses the SoftDeletes trait - articles are not permanently removed from the database
  • The deleted_at timestamp is set when the article is deleted
  • All associated images are permanently deleted from file storage
  • All image database records are permanently deleted
  • Uses database transactions to ensure atomicity (all or nothing)
  • Laravel’s route model binding handles non-existent IDs
  • If any part of the deletion fails, the entire operation is rolled back
Image Files are Permanently Deleted: While the article record can be recovered (soft delete), associated image files are permanently removed from storage and cannot be recovered.

Recovery

Since this is a soft delete, database administrators can recover deleted articles by updating the deleted_at column:
-- Recover a soft-deleted article
UPDATE articles SET deleted_at = NULL WHERE id = 1;
Image files cannot be recovered after deletion. Only the article metadata can be restored.
Source Code Reference: ArticleController::destroy() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:297

Build docs developers (and LLMs) love