laracasts / PHP-Vars-To-Js-Transformer

Transform PHP data to JavaScript.
https://packagist.org/packages/laracasts/utilities
MIT License
2.21k stars 219 forks source link

anything other than window cuz undefined error & temp fix. #80

Closed ctf0 closed 7 years ago

ctf0 commented 8 years ago

currently if we used any other namespace than window we would get Uncaught ReferenceError: namespace_name is not defined

so to fix that we would use

// Providers/AppServiceProvider.php
public function boot()
    {
       // ...
       JavaScript::put([
            'the_var_name' => null,
            // any more vars u use
        ]);
    }

so now everything works as expected and no more errors.

demonmind commented 8 years ago

change the namespace in javascript.php under config folder to whatever you need it to be. Worked for me

ctf0 commented 8 years ago

have u checked the devtools console ?, without the above way around u should get an error

demonmind commented 8 years ago

I got that error and then declaring the namespace in javascript.php fixed the issue. The issue i have now is the variable value is escaped when rendered in the html and does not look like a json string.