Skip to content

Instantly share code, notes, and snippets.

@summerblue
Created August 11, 2014 03:47
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/47db3ce1555c1ffb63c6 to your computer and use it in GitHub Desktop.
Save summerblue/47db3ce1555c1ffb63c6 to your computer and use it in GitHub Desktop.
<?php
use Phphub\Core\CreatorListener;
class TopicsController extends \BaseController implements CreatorListener
{
public function __construct()
{
$this->beforeFilter('auth', ['only' => 'create', 'store']);
}
public function index()
{
$topics = Topic::all();
return View::make('topics.index', compact('topics'));
}
public function create()
{
$node = Node::where('name', '=', Input::get('node'))->where('parent_node', '!=', '')->first();
$nodes = Node::allLevelUp();
return View::make('topics.create', compact('nodes', 'node'));
}
public function store()
{
return App::make('Phphub\Topic\TopicCreator')->create($this, Input::except('_token'));
}
public function show($id)
{
$topic = Topic::findOrFail($id);
return View::make('topics.show', compact('topic'));
}
public function edit($id)
{
$topic = Topic::find($id);
return View::make('topics.edit', compact('topic'));
}
public function update($id)
{
$topic = Topic::findOrFail($id);
$validator = Validator::make($data = Input::all(), Topic::$rules);
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
$topic->update($data);
return Redirect::route('topics.index');
}
public function destroy($id)
{
Topic::destroy($id);
return Redirect::route('topics.index');
}
/**
* ----------------------------------------
* CreatorListener Delegate
* ----------------------------------------
*/
public function creatorFailed($errors)
{
return Redirect::to('/');
}
public function creatorSucceed($topic)
{
Flash::success('话题创建成功.');
return Redirect::route('topics.show', array($topic->id));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment