本文介绍了如何在Laravel 4中对路由组应用多个过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2种类型的用户:
- 内部
- 发行人
对于Internal
,我有2个小组:
- 管理员
- 常规
对于Distributor
,我有4个小组:
- 黄金
- 银
- 青铜
- oem
OEM分销商仅可使用5条路线.
OEM Distributor are eligible for only 5 routes.
Route::get('distributors/{id}', array('before' =>'profile', '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');
常规分销商可使用8条路线.
Regular Distributor are eligible for 8 routes.
Route::get('distributors/{id}', array('before' =>'profile', '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');
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');
- filters.php
- routes.php .
- filters.php
- routes.php.
- 有人可以帮助我,或者至少将我引导到正确的方向吗?
- Can someone please help me or at least direct me to the right direction ?
- 直接在 routes.php 中检查您的
- 不要在检查用户类型条件之前忘记检查Auth :: check()
- 为OEM执行此操作,重复为非OEM执行相同的逻辑.
- check your
Auth::user()->type
right in your routes.php - Don't forget to check Auth::check() before checking the user type condition
- Do it for OEM and repeat the same logic for non OEM.
推荐答案
根据您的情况...
我建议:
Auth::user()->type
这是代码-请进行修改以满足您的确切需求.
Here 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
}
这篇关于如何在Laravel 4中对路由组应用多个过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!