0

I have recently created a plugin (using the 'builder plugin') where I have a field for attaching images (using 'media finder widget'). Everything is working fine - I can upload an image or choose one from the media library. After successful saving, when I go back to the recently saved record, the image isn't shown... How can I fix this?

Thanks!

daru79
  • 31
  • 1
  • 9
  • it would be nice if you are able to share : fields.yaml of you model it will be in you plugin folder > your model > folder with same name of you model > fields.yaml , also if possible share your model's code as well as so we can understand better – Hardik Satasiya Nov 03 '17 at 07:10

2 Answers2

2

From what I found the media finder doesn't save the image in a relationship but records the URL of the image from the media library, this is why using:

public $attachOne = [
   'avatar' => 'System\Models\File'
];

Doesn't work. you actually have to add a field in the DB to record the image path.

If someone else has a better solution go with them, but this allowed me to keep the image.

Bryce
  • 21
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/18703204) – Gilles Gouaillardet Feb 03 '18 at 02:25
  • The answer is that they need to add the field in the DB to record the image path – Bryce Feb 15 '18 at 11:57
  • I would add to your answer that you don't need a relatinoship.if you add the field in the database. It made me be a bit crazy about it. – Federico J. Oct 11 '20 at 17:01
1

'media finder widget' not working with relation type 'file attachment', like this:

public $attachOne = [
   'avatar' => 'System\Models\File'
];

try to use another type (for example: json)

Ngg
  • 26
  • 2