request = $request; } /** * Execute the job. * * @return void */ public function handle() { $compilation = Compilation::create([ 'title' => $this->request->getTitle(), 'published' => $this->request->getPublished(), 'position' => 1, 'category_id' => $this->request->getCategory() ]); $map = array_map(function ($product) { return $product['id']; }, $this->request->products ?? []); if (!empty($map)) { $compilation->products()->attach($map); } } }