[Solved] How to get current Bitcoin rate by dollars [closed]


Hope it’s would be helpful and let me know if there is any other issues.

if (!function_exists("getCurrentBtcDollar")) {
    function getCurrentBtcDollar() {
        //
        $url="https://bitpay.com/api/rates";
        $json=json_decode( file_get_contents( $url ) );
        $btc=0;

        foreach( $json as $obj ){
            if( $obj->code=='USD' )$btc=$obj->rate;
        }

        return $btc;
    }
}

Define that function on Laravel helper.
You could create a new PHP file on “App\Https\Helpers\Helpers.php”
And register that files on “composer.json” file on the root of the project.

"autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files": ["app/Http/Helpers/helpers.php"]
    },

Insert that line onto there.
That’s all.
Regards

2

solved How to get current Bitcoin rate by dollars [closed]