Skip to content

Instantly share code, notes, and snippets.

@freshface
Created September 30, 2016 09:24
Show Gist options
  • Save freshface/045d803f0b55680ca97ffa92f78a1f08 to your computer and use it in GitHub Desktop.
Save freshface/045d803f0b55680ca97ffa92f78a1f08 to your computer and use it in GitHub Desktop.
CreateContentBlockHandler
public function handle(CreateContentBlock $createContentBlock)
{
$createContentBlock->contentBlock = ContentBlock::create(
$this->contentBlockRepository->getNextIdForLanguage($createContentBlock->language),
$createContentBlock->userId,
$this->getNewExtraId(),
$createContentBlock->language,
$createContentBlock->title,
$createContentBlock->text,
!$createContentBlock->isVisible,
$createContentBlock->template,
$createContentBlock->image
);
$image = $createContentBlock->contentBlock->getImage();
// Generate a unique name for the file before saving it
$imageName = md5(uniqid()) . '.' .$image->guessExtension();
$createContentBlock->contentBlock->setImage($imageName);
// Move the file to the directory where brochures are stored
$image->move(
'test',
$imageName
);
$this->contentBlockRepository->add($createContentBlock->contentBlock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment