title: Adding currency picker to laravel
body: <p>I want to have a drop-down in my navbar where I can select a currency and all the prices in my app convert to selected currency, I know I should use middle-ware for this matter but I don't know how to begin. I am using <a href="https://fixer.io/" rel="noreferrer">Fixer</a> with <a href="https://github.com/florianv/laravel-swap" rel="noreferrer">laravel-swap</a> as a package for exchange rates.</p>
  
  <h2>What I've done</h2>
  
  <p>I have made a middleware named it <code>Currancy</code> and it's content:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Closure;
  use Swap\Swap;
  use Swap\Builder;
  
  class Currancy
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @return mixed
       */
      public function handle($request, Closure $next)
      {
          if (Session::has('appcurrency') AND array_key_exists(Session::get('appcurrency'), Config::get('currencies'))) {
              $currency = Session::get('appcurrency'); 
              App::setLocale($currency);
          }
          else {
            App::setLocale(Config::get('app.currency'));
          }
          return $next($request);
      }
  }
  </code></pre>
  
  <p>I also made a <code>currencies.php</code> in config folder:</p>
  
  <pre><code>&lt;?php
  
  return [
    'IDR' =&gt; [
        'name' =&gt; 'Indunesian Rupiah',
    ],
    'USD' =&gt; [
        'name' =&gt; 'U.S Dollar',
    ],
    'EUR' =&gt; [
        'name' =&gt; 'Euro',
    ],
  ];
  </code></pre>
  
  <p>I also added this to my <code>config\app.php</code></p>
  
  <pre><code>'currency' =&gt; 'IDR',
  </code></pre>
  
  <p>in that case my default currency is <code>IDR</code> unless user select others.</p>
  
  <blockquote>
    <p>PS: for my middleware and config file I've got the idea of language
    translation and I don't have an idea how to join it to <code>SWAP</code> package in
    order to work! :\</p>
  </blockquote>
  
  <h1>Questions</h1>
  
  <ol>
  <li>Is the way I try to handle currencies correct way?</li>
  <li>What else should I do for the next step?</li>
  </ol>
  
  <p>thanks.</p>