Endpoint
Description
Updates an existing article by ID. This endpoint allows administrators to modify article details and replace associated images. The endpoint:- Validates all input data according to business rules
- Updates the article record in a database transaction
- Replaces existing images with new ones if provided
- Returns the updated article with all relationships
When images are provided in the update request, ALL existing images are deleted and replaced with the new ones. To keep existing images, don’t include the
images field in the request.Authentication
Bearer token for authentication. Format:
Bearer YOUR_JWT_TOKENUser must have the Admin role. Regular users will receive a 403 Forbidden response.
Headers
Must be
multipart/form-data when uploading images, or application/json for data onlyLanguage preference for response messages. Supported values:
en, esResponse content type
Path Parameters
The unique ID of the article to update
Request Body Parameters
Name of the articleValidation Rules:
- Required
- Must be a string
- Minimum 3 characters
Detailed description of the articleValidation Rules:
- Required
- Must be a string
- Minimum 10 characters
- Maximum 255 characters
Price of the articleValidation Rules:
- Required
- Must be numeric
- Minimum value: 0
ID of the category this article belongs toValidation Rules:
- Required
- Must exist in the categories table
ID of the subcategory this article belongs toValidation Rules:
- Required
- Must exist in the subcategories table
Array of image files to upload (will replace ALL existing images)Validation Rules:
- Optional (nullable)
- Must be an array if provided
- Each image must meet the following criteria:
- Must be a valid image file
- Allowed formats: jpeg, png, jpg
- No maximum size limit (removed in update validation)
Response
Success Response (200 OK)
Always
true for successful requestsSuccess message indicating the article was updated
Example Request
Example Response
Success (200 OK)
Error Responses
401 - Unauthorized
403 - Forbidden (Not Admin)
404 - Not Found
422 - Validation Error
500 - Internal Server Error
Implementation Notes
- Uses database transactions to ensure atomicity
- When new images are uploaded:
- All existing images are deleted from storage
- All existing image records are deleted from database
- New images are uploaded and associated with the article
- If no images are provided, existing images remain unchanged
- Laravel’s route model binding automatically handles 404 for non-existent article IDs
- Old image files are permanently deleted from storage when replaced
- Update validation is similar to create but without the 2MB size limit on images
Source Code Reference:
ArticleController::update() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:226Validation Rules: UpdateArticleRequest at /home/daytona/workspace/source/app/Http/Requests/ArticleRequest/UpdateArticleRequest.php:24