Goal: I want to make route filter in Laravel 4 using
Route::group
andRoute::filter
According to your situation ...
I suggest:
Auth::user()->type
right in your routes.phpHere is the code - please modify to fit your exact needs.
// OEM Routes
if(Auth::check()){
if ( (Auth::user()->type == "Distributor") AND (Auth::user()->distributor()->first()->type == 'OEM') ){
Route::group(array('before'=>'auth'),function() {
Route::group(array('before'=>'csrf'), function(){
// Other important routes like sign-out, dashboard, or change password should also listed here
Route::get('/account/sign-out',array('as'=>'account-sign-out','uses'=>'AccountController@getSignOut' ));
Route::get('/dashboard', array('as' =>'dashboard','uses'=>'HomeController@dashboard'));
// Allow routes
Route::get('distributors/{id}', array('uses'=>'DistributorController@show'));
Route::get('distributors/{id}/edit', 'DistributorController@edit');
Route::put('distributors/{id}/update', array('as'=>'distributors.update', 'uses'=>'DistributorController@update'));
Route::get('catalog_downloads','CatalogDownloadController@index');
Route::get('catalog_downloads/{id}/download','CatalogDownloadController@file_download');
});
}
}else{
return Redirect::route('home'); // I assume you have this declare somewhere
}
// Not OEM Routes
if(Auth::check()){
if ( (Auth::user()->type == "Distributor") AND (Auth::user()->distributor()->first()->type !== 'OEM') ){
Route::group(array('before'=>'auth'),function() {
Route::group(array('before'=>'csrf'), function(){
// Other important routes like sign-out, dashboard, or change password should also listed here
Route::get('/account/sign-out',array('as'=>'account-sign-out','uses'=>'AccountController@getSignOut' ));
Route::get('/dashboard', array('as' =>'dashboard','uses'=>'HomeController@dashboard'));
// Allow routes
Route::get('marketing_materials','MarketingMaterialController@index');
Route::get('marketing_materials/{id}/download/thumb_path','MarketingMaterialController@thumb_download');
Route::get('marketing_materials/{id}/download/media_path','MarketingMaterialController@media_download');
Route::get('distributors/{id}', array('uses'=>'DistributorController@show'));
Route::get('distributors/{id}/edit', 'DistributorController@edit');
Route::put('distributors/{id}/update', array('as'=>'distributors.update', 'uses'=>'DistributorController@update'));
Route::get('catalog_downloads','CatalogDownloadController@index');
Route::get('catalog_downloads/{id}/download','CatalogDownloadController@file_download');
});
}
}else{
return Redirect::route('home'); // I assume you have this declare somewhere
}