Different panel for each user with different roles
Hi guys, I want to hear from you what is the best way to create a checking for the user role and redirect to its own panel? For example, I have three roles and I might have more on the future: administrator, costumer, developer.
The thing is that I want to avoid breaking the open/closed principle having to edit somewhere everytime I need to add a new panel to an user role.
If it where you, what would you do in L5.1?
@biha You could add a method to your role model to return the name of the dashboard view to use. You could enforce the presence of this method with an interface, and that way you don’t have to edit middleware classes or whatever each time you add a new role.
class Role extends Model
{
public function getDashboardView()
{
return sprintf('dashboards.%s', $this->slug);
}
}
class DashboardController extends Controller
{
public function index()
{
return view(Auth::user()->role->getDashboardView());
}
}