I used builder to create this plugin.
Uploaded image with file upload and using public attachOne is not displayed in FrontEnd.
I use this type for image upload all the time and it works perfectly. But this time is something wrong.
database
cover_img | (tried with _string_ and with _text_)
model.php
public $attachOne = [
'cover_img' => 'System\Models\File'
];
Records list
{% for record in records %}
{{record}} {#this returns all parameters except cover_img#}
{{record.cover_img}} {#this returns nothing#}
{% endfor %}
File attachments work using relationships, not DB columns. See https://github.com/octobercms/docs/commit/12948c7b46d09443935e4f0f23bcacf2b8152346. Remove the column from your table's schema entirely.
@mskraban
File attachments work using relationships, not DB columns
... unless you decide to explicitly use DB columns instead of relations.
To do it, declare your file column as string, and avoid using the relationship for file attachment at all.
In the backend use MediaFinder widget for forms, and it will save to the database a string (path relative to media folder), and correctly display thumbnails when editing existing records.
I prefer using images / files this way in October, rather than with "attachOne/attachMany" relationship. I even use it inside repeater/jsonable database columns with excellent results. Maybe @LukeTowers or others can point to some downsides of that approach that I fail to see. It makes life easy for me, allowing e.g. easy database export/copying (all file / image info is in my main table for any plugin), and using the file paths from a string column in templates is dead easy with the {{ path | media }} filter.
Problem solved. I automatically create DB columns for each property field every time I create plugin with builder. I totally forgot to remove DB columns that have attachOne/attachMany relationship.
... unless you decide to explicitly use DB columns instead of relations.
Of course, but then at that point they are not "file attachments", they are mediafinder fields 馃槤
File Attachments and the Media Library serve different purposes, and it's up to the individual developers as to which one meets their needs better. As a general rule of thumb, if you need files / images to only ever be associated with one record, or if you need them to be protected so that only backend users can download them after they've been updated then File Attachments are the way to go. If however you need the files / images to be associated with multiple records or content and are fine with full public access to those files the Media Library is a fine choice.
Most helpful comment
Of course, but then at that point they are not "file attachments", they are mediafinder fields 馃槤
File Attachments and the Media Library serve different purposes, and it's up to the individual developers as to which one meets their needs better. As a general rule of thumb, if you need files / images to only ever be associated with one record, or if you need them to be protected so that only backend users can download them after they've been updated then File Attachments are the way to go. If however you need the files / images to be associated with multiple records or content and are fine with full public access to those files the Media Library is a fine choice.