0

I have a site already developed in Laravel 5.5 and trying to implement React preset in it, but I want to send the variables I use in Blade to the React components to do the rendering.

I installed laracasts/utilities and followed the instructions here https://github.com/laracasts/PHP-Vars-To-Js-Transformer changing the namespace to reactBinding but it isn't working as expected.

On Laravel I do:

JavaScript::put([
    'foo' => 'bar',
    'age' => 29
]);

When running console.log(window) I can see it has the spacename I created with the corresponding values, but console.log(window.reactBinding) and console.log(reactBinding) are both undefined.

Any idea what I could be missing? Is there any extra step to make it work in React? Is there a better way to send variables from Laravel controllers to React components?

1 Answer 1

1

Solved it.

I was including the JS codes in the wrong order. As logic indicates, the view used to prepend the code from PHP-Vars-To-Js-Transformer must be place before the app.js inclusion.

My bad!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.