Endpoint
Description
Creates a new article in the database with optional image uploads. This endpoint is restricted to administrators only. The endpoint:- Validates all input data according to business rules
- Creates the article record in a database transaction
- Uploads and associates images if provided
- Returns the created article with all relationships
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
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 uploadValidation 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
- Maximum size: 2048 KB (2 MB) per image
Response
Success Response (201 Created)
Always
true for successful requestsSuccess message indicating the article was created
Example Request
Example Response
Success (201 Created)
Error Responses
401 - Unauthorized
403 - Forbidden (Not Admin)
422 - Validation Error
500 - Internal Server Error
Implementation Notes
- Uses database transactions to ensure atomicity (article + images created together or not at all)
- Images are stored with the prefix
article_imagein thearticlesdirectory - Image filenames include the article ID and timestamp for uniqueness
- Maximum of 2MB per image file
- If transaction fails, all changes (including uploaded images) are rolled back
- Uses the
HandleImageUploadstrait for consistent image management
Source Code Reference:
ArticleController::store() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:82Validation Rules: CreateArticleRequest at /home/daytona/workspace/source/app/Http/Requests/ArticleRequest/CreateArticleRequest.php:24