Replies: 1 comment 1 reply
-
If I have an Attachment Observer what is the easiest way to get the attachmentable_type from it? I see the Attachment Model has a relationships() method but I don't understand the Dashboard::model portion of this: Having this would allow me to grab thumbnail dimensions defined in the model, and I think is the solution I am looking for. But is this the best way? Another question, is there any way to get Orchid to save to multiple disks? Are singular Picture fields meant to be attachable? It seems to work a little different than Upload field when using a CDN filesystem. In summary I am simply trying to create multiple thumbnails for each uploaded image and save them all to CDN but so far have run into limitations with onSave(), overriding Resource class, and even a custom Generator Engine (since it does not seem to provide a way to determine the attachmentable_type). Is my main issue that Attachments are created at time of upload, while the attachmentable table is only set when the record is created? Will I never know attachmentable_type even with an Observer because attachmentable record is never created until after the file is uploaded and the user clicks to Save? Is this avoidable if you prevent uploads until after the Resource record is created? Please suggest a way to solve this. |
Beta Was this translation helpful? Give feedback.
-
I am trying to generate thumbnails whenever images are uploaded. I am using s3 disk.
I was able to get this working with Screen createOrUpdate() using multiple files from Upload field.
I was NOT able to get this working with Resource onSave() with the Picture field:
Picture::make('image_upload') ->title('Image Upload') ->storage(config('platform.attachment.disk')) // s3 ->groups('photos'),
When I try to sync the Resource's attachment it never adds a row to the attachmentable table and throws an error with the CDN URL.
public function onSave(ResourceRequest $request, Model $model) { $model->forceFill($request->all())->save(); $model->attachment()->sync( //syncWithoutDetaching $request->input('image_upload', []) // error here );
@tabuna Is there a simpler way to handle this? Any help appreciated. How are you supposed to tell when an attachment is uploaded? Would I be better off trying to take the approach of creating an Attachment Observer to handle generating thumbnails?
For clarity for the Picture field I am able to get a record saved into the attachments table but it errors out trying to record to the attachmentable table and outputs the CDN URL.
Beta Was this translation helpful? Give feedback.
All reactions