Skip to content

Instantly share code, notes, and snippets.

@mateusgf
Last active December 20, 2015 07:28
Show Gist options
  • Save mateusgf/6093179 to your computer and use it in GitHub Desktop.
Save mateusgf/6093179 to your computer and use it in GitHub Desktop.
// Nossa ação de editar também deve ser protegida!
public function __construct() {
$this->filter('before', 'auth')->only(array('create', 'your_questions', 'edit'));
}
public function get_edit($id = NULL) {
if (!$this->question_belongs_to_user($id)) {
return Redirect::to_route('your_questions')->with('message', 'Invalid Question');
}
return View::make('questions.edit')
->with('title', 'Make It Snappy Q&A - Edit')
->with('question', Question::find($id));
}
private function question_belongs_to_user($id) {
$question = Question::find($id);
if ($question->user_id == Auth::user()->id) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment