title: Laravel Global Middleware to set Country Value failed in its logic
body: <p>Im working on a Laravel Global Middleware to set Country Value in a Cookie when web visitors access the website.</p>
  
  <p>For that reason I create the following function:</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      if(!$request-&gt;cookies-&gt;has('geo'))
      {
          if (!$request-&gt;cookies-&gt;has('geo') &amp;&amp; GeoIP()-&gt;getLocation()-&gt;iso_code !== null) {
              //find customer IP location
              $code = strtolower(GeoIP()-&gt;getLocation()-&gt;iso_code);
              // creates a cookie with iso_code value
              $cookie = cookie('geo', $code, 600);
              //move to page
              return $next($request)-&gt;cookie($cookie);
          }
          else{
              return response()-&gt;view('static.select-country');
              //move to page
              return $next($request);
          }
      }
      if ($request-&gt;cookies-&gt;has('geo')) {
          //move to page
          return $next($request);
      }
  }
  </code></pre>
  
  <p>1- If cookie 'geo' is null:</p>
  
  <ul>
  <li>First: cookie 'geo' is null and Torann GeoIp detector is not null -> create a cookie with country ISO_CODE</li>
  <li>Else (geo cookie is null &amp;&amp; GeoIP detector is null) -> go to page select-country.phtml in order to choose your country and set the cookie manually.</li>
  </ul>
  
  <p>2- If cookie geo is not null code: ($request->cookies->has('geo')) </p>
  
  <ul>
  <li>Visitor already has a cookie -> move to page.</li>
  </ul>
  
  <p>(my idea for step 2 is for existing customers that already have a country (already have a cookie with that value) but they want to change manually the country in static.select-country view and avoid GeoIP detector override by loop 1.)</p>
  
  <p>My problem: at this moment when customer choose manually in static.select-country view, it moves to page home:</p>
  
  <ul>
  <li>But the application assign a cookie with GeoIP detector instead of take into consideration manually selected country (cookie created in static.select-country) by customer.</li>
  </ul>