This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

mattm
mattm

I created a Model and Database and can upload an image in the Backend Columns using the Media Finder. But after uploading, no image path is saved to the database in the photo column.

Media Finder


I added $attachOne to Model.

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

I set Media Finder field as photo in fields.yamal.

Fields


Database Tables

  • id (integer)
  • title (string)
  • photo (string) (image path)

Twig

{% for product in builderListCatalog.records %}
    {{ product.title }}
    <img src="{{ product.photo }}" />
{% endfor %}

This successfully displays the Title but not the Photo path because it is empty in the database.

Last updated

mailyura24071
mailyura24071

The photo field in the database is not needed.

In the template, enter {{ product.photo.path }} or {{ product.photo.thumb(500,auto) }} etc.

mattm
mattm

It does not display the image.

In the backend, after I upload and go back to the entry, the photo is missing.

upload

mailyura24071
mattm
mattm

mailyura24071 said:

Watch the video

http://watch-learn.com/video-tutorials/making-websites-with-october-cms-part-09-images-and-galleries

I did all of that, it is not working. What am I missing?


1

Created Model, added:

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

2

Added Media Finder to fields.yamal.

fields


3

Set Field Name to photo.

Field


4

Upload image in backend using Media Finder. Uploads to media directory.

upload


5

Save and Refresh, image is missing. Does not display with Twig. Path nowhere in database.

upload

Last updated

mattm
mattm

mailyura24071 said:

Watch the video

http://watch-learn.com/video-tutorials/making-websites-with-october-cms-part-09-images-and-galleries

It looks like I got it solved.

I removed public $attachOne and added photo column to the database.

K.Singh
K.Singh

how to show that photo at frontend .i did all of that show in http://watch-learn.com/video-tutorials/making-websites-with-october-cms-part-09-images-and-galleries

this link but it not showing any path or whatever to say is printed after typing {{record.photo}}

and i am not using file upload instead of media finder

Last updated

guillaume.batier2373
guillaume.batier2373

Same issue.

If your image fiel is and upload field you've have to use {{product.photo.path}} or if it's a media finder use this {{product.photo}}|media

https://octobercms.com/docs/markup/filter-media ;)

hojamov129851298
hojamov129851298

Remove this from your model:

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

and crearte photo field on your database table

imjignesh262011
imjignesh262011
  1. You can remove the code public $attachOne = [ 'photo' => 'System\Models\File' ]; from your plugin file.
  2. Add photo column of type String (Nullable) in your table This will work as normal.

1-10 of 10

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.