i am create a currency converter middleware in laravel based on subdomain wise, app/Http/Middleware/Currency.php this middleware is used to convert currency
namespace App\Http\Middleware;
use Closure;
class Currency
{
public function convert($request, Closure $next)
{
$sub=array_shift((explode('.', $_SERVER['HTTP_HOST'])));
$fromCurrency = "AED";
$toCurrency = "$sub";
$amount = "1";
$url = "https://www.google.com/search?q=".$fromCurrency."+to+".$toCurrency;
$get = file_get_contents($url);
$data = preg_split('/\D\s(.*?)\s=\s/',$get);
$exhangeRate = (float) substr($data[1],0,7);
$convertedAmount = $amount*$exhangeRate;
$data = array( 'exhangeRate' => $exhangeRate, 'convertedAmount' =>$convertedAmount, 'fromCurrency' => strtoupper($fromCurrency), 'toCurrency' => strtoupper($toCurrency));
return json_encode( $data );
}
}
and write in Kernel.php like
protected $middleware = [
\App\Http\Middleware\Currency::class,
];
and show Function name must be a string error also in page, how to access this return value in controller?