title: How to create a filter for a domain in Laravel
body: <p>I am trying to create a filter that works for a specific domain and redirects a user from any page they try to visit if they have gone over a quota. So far, the code does not redirect at all.</p>
  
  <p>Here is what I have so far in <code>filters.php</code>:</p>
  
  <pre><code>Route::filter('domain', function () {
      if (stripos(Request::root(), Config::get('domains.main')) !== false) {
          if (Auth::check()) {
              $user = Auth::user();
  
              $max_quota = Plan::where('id', $user-&gt;plan_id)-&gt;where('is_active', true)-&gt;pluck('max_quota');
  
              $quota_used = Quota::where('user_id', $user-&gt;id)-&gt;count();
  
              if (empty($max_quota)) {
                  return Redirect::to('account/error/inactive');
              } elseif ($quota_used &gt;= $max_quota) {
                  return Redirect::to('account/error/over_quota');
              }
          }
      }
  });
  </code></pre>
  
  <p>Even if I put this in <code>routes.php</code> under:</p>
  
  <pre><code>Route::group(['domain' =&gt; Config::get('domains.main')], function () {
  
      Route::filter('*', function () { /* Same code here... */ });
  
  }
  </code></pre>
  
  <p>It will then get into the filter function, successfully check the criteria, but the redirect still doesn't happen.</p>
  
  <p>I think I am missing more than one key point here. Ideas?</p>