Skip to content
Advertisement

How can I work with React in a Laravel project? [closed]

I started a fresh Laravel project and re-scaffolded it to use React instead of Vue. I have another developer that will be coding the React, but I will be responsible for the Laravel/backend code. I have a few questions. Does React work within blade templates? How do routes in Laravel work if we are using react? Lastly, when I run the start artisan start command, will that also start up React?

Advertisement

Answer

You essentially have the main app page for the PHP side (blade), and you can embed the react inside a div within the blade html. The React frontend configures the DOM virtually and then displays it within that div. Keep the frontend separate from the Laravel backend. PHP artisan serve will start the backend up, while you will need npm run watch for the frontend side. Use Laravel to create the backend API in which the React frontend can make calls to the server for its data needs.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement