Created
August 11, 2014 03:48
-
-
Save summerblue/b9865eb3f78c75c3dfaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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