HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/pietvanmierlo/stempelbv.nl/app/Helpers/GlobalHelpers.php
<?php declare(strict_types=1);
use Illuminate\Support\Facades\App;

if(!function_exists('localized_route')) {
    /**
     * Give this helper a named route, for example site.password.reset and it wil return the translated
     * route of for example nl/wachtwoord/reset for the dutch language. The parameters you can give will
     * be appended in the order given to the translated url. If it does not have a translated route it will
     * prefix the named route with the app language iso2
     *
     * @param string $routeName
     * @param array $parameters
     * @param bool $absolute
     * @return string
     */
    function localized_route(string $routeName, array $parameters = [], $absolute = true): string {
        $languageIso2 = App::getLanguage()->iso_2;
        $base = url('/');

        if(array_key_exists($routeName, __('site/routes'))) {
            $routeTranslationName = __('site/routes')[$routeName];
            $url = url($routeTranslationName, $parameters);
            $relativeUrl = substr($url, mb_strlen($base) + 1);
        } else {
            $url = route($routeName, $parameters, $absolute);
            $relativeUrl = substr($url, mb_strlen($base) + 1);
        }

        if($absolute) return implode('/', [$base, $languageIso2, $relativeUrl]);
        return implode('/', ['/'.$languageIso2, $relativeUrl]);
    }
}