<?php

namespace App\Http\Middleware;

use Closure;
use Session;
use App\Config;

class Currency
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //$exrate      = Config::where('id', '=', 1)->first()->first(['exrate']);

        $currarr     = array('rsd','usd');
        $curCurrency = (isset($_SESSION["currency"]) && in_array($_SESSION["currency"],$currarr)) ? strtoupper($_SESSION["currency"]) : 'RSD';


        //Session::put('exrate', $exrate->exrate);
        Session::put('currency', $curCurrency);
        Session::save();

        return $next($request);
    }
}
