Skip to content

Instantly share code, notes, and snippets.

@summerblue
Created August 11, 2014 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save summerblue/b9865eb3f78c75c3dfaa to your computer and use it in GitHub Desktop.
Save summerblue/b9865eb3f78c75c3dfaa to your computer and use it in GitHub Desktop.
<?php namespace Phphub\Topic;
use Phphub\Forms\TopicCreationForm;
use Phphub\Core\CreatorListener;
use Topic, Auth;
class TopicCreator
{
protected $topicModel;
protected $form;
public function __construct(Topic $topicModel, TopicCreationForm $form)
{
$this->userModel = $topicModel;
$this->form = $form;
}
public function create(CreatorListener $observer, $data)
{
$data['user_id'] = Auth::user()->id;
// Validation
$this->form->validate($data);
$topic = Topic::create($data);
if ( ! $topic)
{
return $observer->creatorFailed($topic->getErrors());
}
return $observer->creatorSucceed($topic);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment