brandymedia's avatar

Image path being saved as temporary path

I store an file via a form and it works fine. But then in the update method for some reason it saves the actual file to the storage but it keeps saving a temporary path in the DB.

I've tried debugging the value of $newPathLogo and it returns the correct path until it is merged with the request then it becomes an upload file object.

I'm sure it's something really obvious I'm missing but just can't see it.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The issue you're experiencing is likely due to the way you're merging the new file path into the request data. When you use $request->merge(), it modifies the request object, but it doesn't affect the original data that is being passed to the update() method. This can lead to the temporary file path being saved instead of the new path.

To resolve this, you should directly update the $order model with the new path before calling the update() method. Here's how you can modify your code:

Key Changes:

  1. Directly Assign the New Path: Instead of merging the new path into the request, directly assign it to the $order model's logo attribute.
  2. Exclude 'logo' from update(): When calling update(), exclude the 'logo' field from the request data since it's already been set directly on the model.

This approach ensures that the correct file path is saved to the database.

Please or to participate in this conversation.