trevorpan
8 months ago
1705
13
Feedback

withoutSyncingToSearch() - algolia - laravel media library thumbnail image indexing issue

Posted 8 months ago by trevorpan

Hi,

Have been trying to figure out how use the Spatie MediaLibrary and Algolia VueInstantSearch. I've made a few posts on algolia's forum and have discovered we cannot have two models in the same index.

I wanted to see if Laravel's withoutSyncingToSearch() could accomplish this but am getting errors such as:

Symfony\Component\Debug\Exception\FatalThrowableError
Too few arguments to function Illuminate\Database\Eloquent\Model::asJson(), 0 passed in /Users/trevorpan/code/bidbird/app/Job.php on line 415 and exactly 1 expected 

Basically, I'm trying to stall the indexing, locate the job being saved and then insert it into the job index.

Before this approach, I was trying to use the two indexes Job.php and Media.php and concatenate them in the VueComponent such as:

<img :hit="item" attribute="model_id" :src=“'/storage/' + item.model_id + '/conversions/' + item.file_name” :hit="item" attribute="model_id" width=200 height=120   alt=""/>

The above image src is the MediaLibary path. However, it's not the way the package performs in php which is in the block below:

// Job model
/**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {

        $job = SlugJob::asJson()->get()->first(); 
        // ignition suggested the asJson() vs class()

        SlugJob::withoutSyncingToSearch(function ($job) {
            return $imageUrl = $job->getMedia('document')->first()->getUrl('thumbnail');
        });

        return [
...
...
...
            'imageUrl' => $imageUrl,
            'customRanking' => [
                'desc(deadline)'
            ]
        ];
    }

Can you see a way to achieve this goal?

Thank you - have been at this for months off and on. There's got to be a way... Trevor

Please sign in or create an account to participate in this conversation.