public function run() { DB::beginTransaction(); $category = new Category(); $category->save(); $category->saveIcon($this->icon); foreach ($this->translations as $fields) { $fields['slug'] = slug($fields['name']); $category->translations()->create($fields); } if (!empty($this->parentId)) { $parent = Category::find($this->parentId); $parent->addChild($category); } DB::commit(); }