如何在Laravev4.1的过滤器中进行DRY


How can I make DRY in filter.php of Laravel4.1

我使用的是Laravev4.1。

我想在不同的过滤器和相同的对象中进行相同的处理,如下所示。

Route::filter('filter1', function(){
  $sameObject = // I want to fetch sameObject;
  View::share('obj', $sameObject);
});
Route::filter('filter2', function(){
  $sameObject = // I want to fetch sameObject;
  if(isset($sameObject){
    return Redirect::to('home')
  }
});

有什么方法可以使干燥,这就是过程吗?

尝试使用会话或配置(噱头)方法:

Route::filter('filter1', function(){
  $sameObject = // I want to fetch sameObject;
  Config::set('myObject',$sameObject);
  View::share('obj', $sameObject);
});
Route::filter('filter2', function(){
  $sameObject = Config::get('myObject');
  if(isset($sameObject){
    return Redirect::to('home')
  }

});