Overwrite Laravel Helpers

To control http / https related URL generators, some helpers must be overwritten.

Add param in .env:

USE_HTTPS=true

Find helper file:

\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php

if (! function_exists('asset')) {
    /**
     * Generate an asset path for the application.
     *
     * @param  string  $path
     * @param  bool    $secure
     * @return string
     */
    function asset($path, $secure = null)
    {
        //logg(env('USE_HTTPS'));
        if(env('USE_HTTPS') == true){
            $secure = true;
        }
        return app('url')->asset($path, $secure);
    }
}

if (! function_exists('url')) {
    /**
     * Generate a url for the application.
     *
     * @param  string  $path
     * @param  mixed   $parameters
     * @param  bool    $secure
     * @return \Illuminate\Contracts\Routing\UrlGenerator|string
     */
    function url($path = null, $parameters = [], $secure = null)
    {
        if (is_null($path)) {
            return app(UrlGenerator::class);
        }

        if(env('USE_HTTPS') == true){
            $secure = true;
        }

        return app(UrlGenerator::class)->to($path, $parameters, $secure);
    }
}

if (! function_exists('route')) {
    /**
     * Generate the URL to a named route.
     *
     * @param  string  $name
     * @param  array   $parameters
     * @param  bool    $absolute
     * @return string
     */
    function route($name, $parameters = [], $absolute = true)
    {
        $url = app('url');

        if(env('USE_HTTPS') == true){
            $url->forceScheme('https');
        }
        
        return $url->route($name, $parameters, $absolute);
    }
}