3 months ago

Lavarel + composer and a mistake I don't understand.

Posted 3 months ago by legnus

I am a beginner in laravel and would like to ask for your help. I installed the "statickidz / php-google-translate-free" class via "composer" and it worked, but only if I'm at the root of the project (index.php). If I try to use it in a subdirectory file it doesn't work, displaying the error: "syntax error, unexpected 'use' (T_USE) (View: / home / u5799060 / public_html / themes / default / views / frontend / supp / subheader.blade.php) "

The instruction is below, and must be inside the "subheader.blade.php" file but not work:

    require_once ('../vendor/autoload.php');
        use \Statickidz\GoogleTranslate;

        $source = 'bn';
        $target = 'en';
        $text = 'আমি করবো না।';

        $trans = new GoogleTranslate();
        $result = $trans->translate($source, $target, $text);

        echo '<h2>'.$result.'</h2>'

I've already tried:

require_once ('../../vendor/autoload.php'); require_once ('../../../vendor/autoload.php'); require_once ('../../../vendor/autoload.php'); . . . but not work. What's wrong?

Please sign in or create an account to participate in this conversation.