I'm making a Laravel application that includes a role management system, using entrust and confide.
So when a route is browsed (eg /questions), the blade view file that should be displayed depends on the user type. I solved this problem by making a switch in every controller function
public function getQuestions(){
$questions = Question::all();
switch(Auth::User()->getRoleName()){
case 'Moderator':
return View::make('questions.moderator.index',array('questions'=>$questions));
break;
case 'Teacher':
return View::make('questions.teacher.index',array('questions'=>$questions));
break;
case 'Student':
return View::make('questions.student.index',array('questions'=>$questions));
break;
default:
return App:abort(404);
}
}
But I guess this isn't the best way to solve this problem. I'm actually looking for a kind of filtering in the controller.
So my question is: what would be the best way to handle this ?
Thanks