W
W
webfln2017-08-03 18:01:48
Laravel
webfln, 2017-08-03 18:01:48

Create-React-App and Laravel. How to use correctly?

Hello!
The question is most likely for those who have used create-react-app with popular php frameworks like laravel.
I'll try to explain what I want.
Here I have an application in react, which I built using create-react-app.
When the application is launched, it rises to localhost:3000, in the application config I specify the proxy from the backend url, to
access the laravel api.
Now the architecture is:
-..(lara folders)
-..(lara folders)
-react
--node_modules
--public
--src
I want to replace react/public/index.html output with resources/views/index.blade.php , and use server-side data, such as analytics, or authorization status in the template engine itself.
And I can't figure out how to implement it correctly. Previously, when I configured webpack myself, I simply moved the scripts to laravel's public folder. And in the index.blade.php itself, I just wrote the path for the scripts.
I hope I didn't explain badly. Thanks for the help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2017-08-04
@webfln

create-react-app opens creates its own server other than laravel. It is not possible to connect them.
Use laravel as an API.
RestAPI, CORS technologies

F
First Last, 2017-08-03
@shindakioku

Use laravel-mix?
You put js files in resources/assets, in webpack.mix.js you specify where the file/s will be (will be) after assembly
. Open routes/web.php and paste:

Route::any('{all}', function () {
    return view('main');
})->where(['all' => '.*']);

In main.blade.php you will have a simple html:5 with script[src=main_js]. In the main there should be a launch mechanism.
I hope I did not explain crookedly. You are welcome

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question