4

As I have learned a lot for now about React and Laravel, I can of course create a laravel app using

laravel new MyApp

and set the preset to react with

php artisan preset react

Now I can build a nice app with frontend and API.

But is this best practice? I'm wondering if it wouldn't be better to install a react app i.e. with create-react-app and seperate it from laravel as I don't need the whole view stuff in laravel.

1
  • 4
    Simple way is to ask; are you going to have multiple clients? (Webapp, iOS app, Android app) if not; go with preset from Laravel. Another metric is, do you have teams dedicated to backend and frontend? If so, go without the preset and use create react-app. Commented Nov 29, 2018 at 10:14

1 Answer 1

2

Building with React CLI create-react-app

  1. You can host your website with static hosting server which is far more cheaper for more traffic scenario.
  2. Although separate php server his required to host api part with laravel but, these api can be used in mobile apps. You may host on single server with a subdomain.
  3. SEO will be a headache. You will need a separate nodejs function to inject the seo tags or any other way.
  4. As you frontend and backend is isolated, your system will be a bit safer from backend/admin panel vulnerabilities. You just need to secure all your apis.

Building within laravel php artisan preset react

  1. Easy SEO part with server side rendering possible using laravel.
  2. Single server, single domain easy to maintain.
Sign up to request clarification or add additional context in comments.

3 Comments

How to deal with authentication when Frontend is isolated from laravel?
@RuslanGonzalez its an off topic question to be covered separately. Anyway you meed to create an endpoint for auth check with cookie (fortify way of handling auth). Redirect user from js app to laravel with temporary token, get user authenticated, and get another call back token. Then from frontend app make api call (cors enabled) with those 2 initial tokens to get access token… Due to all these i dont prefer this at all. Or you need to search some grant type auth app in laravel like auth0
Sorry for my too late answer, I agree, this is definitely off-topic question. Although I already figured out how to manage it using SANCTUM origins and credentials on CORS setup. It wasn't really intuitive but we figured out, and it's as secure as the Laravel defaults. Again thank you so much for your answer, wasn't to far of my actual approach.

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.