Update entry
Updates an existing diary entry. Only the creator of the entry can perform updates. Supports updating text content, visibility, image attachments, and friend sharing.Endpoint
Authentication
This endpoint requires authentication via theauth middleware. Additionally, the authenticated user must be the creator of the entry to perform updates.
Path parameters
The ID of the entry to update. Laravel route model binding automatically resolves this to an Entry instance.
Request parameters
The updated text content of the diary entry.
The updated visibility setting for the entry.
An optional image file to replace the existing attachment. If a new file is uploaded, the previous image (if any) will be deleted from storage and replaced with the new one.
An optional array of friend user IDs to share this entry with. This will sync the friend associations, replacing any previous sharing settings.
Authorization
The endpoint checks if the authenticated user is the creator of the entry:not_your_entry error message.
Response
On successful update, the user is redirected to the home session with an update confirmation message.Returns
update_entry on successful entry update.The unique identifier of the updated entry.
The updated text content of the entry.
The updated visibility setting of the entry.
The timestamp when the entry was last updated.
Example request
Image handling
The update endpoint handles image attachments with three scenarios:- New file uploaded: If a new file is provided, any existing image is deleted from storage and the database, then the new image is stored and associated with the entry.
-
File explicitly removed: If no file is uploaded and the
fileinput is explicitly empty, any existing image is deleted. - No change: If no file parameter is sent, the existing image remains unchanged.
Friend sharing
Thesync() method is used to update friend associations, which replaces all previous associations with the new set of friend IDs provided in the request.