you can also create an 'after' filter and simply redirect the user
Route::group(['before' => 'auth], function () {
Route::group(['after' => 'HR'], function () {
//
});
});
better would be to handle the redirection in
DashboardController@redirect
because the URI is the same e.g. '/dashboard' so there is no way for a user to land on the wrong dashboard
zenry : The after filter doesn't work! and you can guess I have lots of methods in each controller. SO resolving them to a single DashboardController would not work as different user types have completely different views and functionality. I just want them to see that they are at /dashboard.
Joker666 said:
zenry : The after filter doesn't work! and you can guess I have lots of methods in each controller. SO resolving them to a single DashboardController would not work as different user types have completely different views and functionality. I just want them to see that they are at /dashboard.
yes, I forgot the after filter is done after the request
does this work?
Route::filter('userType', function() {
switch(Auth::user()->type)
{
case 'MD':
Session::put('user.dashboard', 'MDProfileController@index');
break;
case 'DME':
Session::put('user.dashboard', 'DMEController@index');
break;
}
});
Route::group(['before' => 'auth|userType'], function() {
Route::get('dashboard', [
'as' => 'dashboard',
'uses' => Session::get('user.dashboard', 'FallbackController@dashboad')
]);
});
It doesn't work at the first attempt. Goes to the fallbackcontroller. but when I reload it takes me to the desired controller's view. How to solve that?
And bigger question is even if i solved it using filter like this. it redirects me to the index of the controllers, but I have other methods(not put in the code because it will get bigger), how to do that. Using all the routing logic in the filter is bad coding I guess.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community