<?php namespace App\Jobs; use App\Models\Goods; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; class SyncGoodsToEs implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $goods; /** * Create a new job instance. * * @return void */ public function __construct(Goods $goods) { $this->goods = $goods; } /** * Execute the job. * * @return void */ public function handle() { $data = $this->goods->toEsArray(); app('es')->index([ 'index' => 'goods', 'type' => '_doc', 'id' => $data['id'], 'body' => $data, ]); } }