wiwa1978
wiwa1978

Reputation: 2687

Laravel: changing from Blade to JS frontend framework

I have a Laravel application which is using Blade as the frontend. I'm feeling the better (more future proof) option would be to switch to Angular, Vue or React, (not entirely sure yet which one I will use but that's not the question of this post)

I've always thought that the backend code should expose an API in order for these JS frontend frameworks to work. I currently don't expose any sort of API.

I basically designed it in the normal way:

  1. define route pointing to controller
  2. create controller function and direct it to a view
  3. create the Blade view

Couple of questions:

  1. Should I redesign my backend to expose such an API?
  2. Can I call Angular/Vue/React code from my controllers, similar to what I'm doing with Blade?
  3. In case the answer is yes to question 1, shouldn't I consider changing to Lumen then?

Upvotes: 1

Views: 907

Answers (1)

Sherif
Sherif

Reputation: 1537

using frontend framework means you would most likely build you backend as an API, a common scenario is:

  1. a single route the points to a controller which loads the angular/vue app
  2. the angular/vue app would handle views and templates.
  3. once the app is loaded you only need to communicate with the server through the exposed api's

you can't call you js code from laravel controller and you probably won't need to.

as for your question lumen vs laravel, I think it's up to you to decide that. both have pro's con's.

Upvotes: 2

Related Questions