Skip to main content

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

POST /Update/Entry/{entry}

Authentication

This endpoint requires authentication via the auth middleware. Additionally, the authenticated user must be the creator of the entry to perform updates.

Path parameters

entry
integer
required
The ID of the entry to update. Laravel route model binding automatically resolves this to an Entry instance.

Request parameters

body
string
The updated text content of the diary entry.
visibilityValue
string
The updated visibility setting for the entry.
file
file
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.
friend
array
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:
if($entry->creator->id != Auth::user()->id) {
    return redirect()->back()->with('message', 'not_your_entry');
}
If the user is not the creator, they receive a not_your_entry error message.

Response

On successful update, the user is redirected to the home session with an update confirmation message.
message
string
Returns update_entry on successful entry update.
entry.id
integer
The unique identifier of the updated entry.
entry.body
string
The updated text content of the entry.
entry.visibility
string
The updated visibility setting of the entry.
entry.updated_at
timestamp
The timestamp when the entry was last updated.

Example request

curl -X POST https://api.mydiary.com/Update/Entry/42 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "body=Updated: Today was an incredible day!" \
  -F "visibilityValue=private" \
  -F "file=@/path/to/new_photo.jpg" \
  -F "friend[]=789"

Image handling

The update endpoint handles image attachments with three scenarios:
  1. 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.
  2. File explicitly removed: If no file is uploaded and the file input is explicitly empty, any existing image is deleted.
  3. No change: If no file parameter is sent, the existing image remains unchanged.

Friend sharing

The sync() method is used to update friend associations, which replaces all previous associations with the new set of friend IDs provided in the request.

Build docs developers (and LLMs) love