/** * Create an Item, its derived class, tags, and reset the main page cache * * @param $inputs * @return Item $item */ public function create($inputs, $user) { // Create the item $item = $this->itemsRepo->store($inputs, $user); // Save Tags $tags = $this->tagsRepo->store($inputs, $user); if (count($tags)) { // Attach Tags to the Item $item->tags()->attach($tags); } // Create the derived type switch ($inputs['type']) { case 'Link': // Create the Link $link = $this->linksRepo->store($inputs); // Associate it to the Item $link->item()->save($item); // Save it to the search index $this->searchHandler->add($link); break; case 'Note': // Create the Note $note = $this->notesRepo->store($inputs); // Associate it to the Item $note->item()->save($item); // Save it to the search index $this->searchHandler->add($note); break; } // Reset caches $this->cacheHandler->del(CacheHandlerInterface::MAINPAGE); $this->cacheHandler->del(CacheHandlerInterface::TAGS); return $item; }