Routes
// AUTHENTICATED USERS
Route::group(['middleware' => 'auth'], function(){
// Admin Only
Route::group(['middleware' => 'admin'], function(){
Route::get('admin/profile', [
'as' => 'admin.profile',
'uses' => 'ProfileController@index'
]);
});
// Logistics Only
Route::group(['middleware' => 'logistic'], function(){
Route::get('logistics/profile', [
'as' => 'logistic.profile',
'uses' => 'ProfileController@index'
]);
});
// Accountant Only
Route::group(['middleware' => 'accountant'], function(){
Route::get('accountant/profile', [
'as' => 'accountant.profile',
'uses' => 'ProfileController@index'
]);
});
// Client Only
Route::group(['middleware' => 'client'], function(){
Route::get('/profile', [
'as' => 'client.profile',
'uses' => 'ProfileController@clientProfile'
]);
});
// All Authenticated User
Route::get('/check-profile', [
'as' => 'check.profile',
'uses' => 'ProfileController@checkProfile'
]);
});
Profile Controller
public function checkProfile()
{
$role = auth()->user()->role()->first()->label;
if ($role === 'Admin') {
return redirect()->route('admin.profile');
} elseif ($role === 'Logistic Officer') {
return redirect()->route('logistic.profile');
} elseif ($role === 'Accountant') {
return redirect()->route('accountant.profile');
} else {
return redirect()->route('client.profile');
}
}
View
<a href="{{ route('check.profile') }}> </a>
What's the better way right this?
Is this bad practice?