Ad

Getting Deffered Saved Images In Octobercms

- 1 answer

Hi there i m using 'uploader' and sitesearch plugin in octobercms. using uploader plugin i m saving multiple images in my posting model after saving they are showing in the backend area but are not retrieving. i m retrieving attachMany relationship postingimage in this way but when i print {{result.model}} in content.htm file it shows null array like this

{"title":"gdsag","brandname":"Yamaha","description":"gdsga","price":5887,"name":"Rawalpindi","postingimage":[]}

cannot able to get the deffered saved images in model getting images like this in sitesearch plugin

if ($item->postingimage) {
                    return [
                        'title' => $item->title,
                        'text' => $item->description,
                        'text' => $item->price,
                        'text' => $item->brandname,
                        'text' => $item->name,
                        'thumb' => $item->postingimage->first(),

                        'relevance' => $relevance, // higher relevance results in a higher
                        'model' => $item, 
                    ];

my init method in component

public function init()
    {
        $component = $this->addComponent(
            'Responsiv\Uploader\Components\FileUploader',
            'fileUploader',
            ['deferredBinding' => true]
        );


        $component->bindModel('postingimage', new Posting);


    }

i m saving the images in this way after form submisssion

 $posting->save(null, post('_session_key'));

any help?

Ad

Answer

I got the solution for this problem

$matching = Posting::join('fsz_posting_tblbrands') // ... do your join

// Now refetch the needed models with all needed relations
$items = Posting::with('postingimage')->whereIn('id', $matching->pluck('id'))->get();

Also make sure that your $item is actually an instance of your model and not only a Collection. If it is a simple Collection we won't be able to load the relations

Ad
source: stackoverflow.com
Ad