Laravel 5.5 and angular 4 integration - php

I am working on a ERP system that is 6 years old and it is developed in raw PHP maintaining procedural coding structure without OOP or any Framework.
Finally our management decided to re-write the application with upgraded technologies. We will write the application in Laravel Framework. Database will be Oracle and Mysql both. In the front end we will use Angular 4.
The confusion is should i use Angular 4 for front end request handling and data binding? Or i should go with Javascript/Jquery. Last few days i am seeking some suggestions on the net. I found some also. My question is, how should i integrate Laravel and angular? should i go for API based approach maintaining two different project for Laravel and Angular or angular inside Laravel in a folder? If i go for API based approach, will my ajax request increased? The database of the application will be too large.
will API based approach make data loading slower?
All the request in the application will be ajax based and there will be no page refresh approach, but url will change on request.
Please suggest me the possible right solution to help me taking the right decision.

Angular 2/4+ has been designed to build SPA (Single Page Application). If you deep dive into angular then it will be clear to you that all the structures and conventions followed in the angular 2+ architecture are optimized for SPA.
So, if you want to use Angular with Laravel 5+ then I think the best way would be to use angular to build a standalone frontend application and use Laravel 5+ as a backend. That means laravel will act as an API server and a backend of the application.
Using laravel as an API server doesn't necessarily mean your database will be bigger. It is actually upto you how you design your application.
But, there is an another good solution.
You can use VueJs. There is a build in support for VueJs within Laravel 5+.
The benefit of using VueJs is that you can use it just like Jquery. That means you don't have to create separate standalone application for VueJs like Angular.
But, you can use it, page by page basis. It is loosely coupled.
You will get most of the benefit of Angular from it.
You can also use React.

You can use Angular 4 to rewrite your application. Fontend as Single Page Application and Backend exposing REST API will help you to build a good performance application.
I prefer to keep Angular and REST API separate as they should be independent to each other. REST APIs should always be generic so that they can be consumed by other applications too.
Yes, there will be lot of API calls to server. You can scale your REST APIs according to your number of requests. It is better building micro-services to ensure most of the services will not be impacted in case of lot of heavy load (at least part of application will be running). It will help you in future maintenance also.

Related

Confused about Laravel's architecture

I'm a little confused about how exactly I should approach using Laravel. Right now I have a React application that runs through NPM. This then calls restful PHP API's. So more or less my backend and frontend are separate.
In Laravel, it seems that you develop your frontend within Laravel itself (reminding me of applications like WordPress) with it's MVC architecture and routing capabilities.
Should Laravel be used just for API development? Should I be looking to integrate my app (based on create-react-app) into laravel itself? Am I thinking about all this completely incorrectly?
Again forgive what I'm sure is such a newbie question and any resources you could point me to in helping me understand the framework would be great.
An independent UI communicating with an API would be a SPA, Single Page App. And depending on the size or complexity of your application, that's a completely valid way to go. Especially if you can conceive of a non-browser platform like a mobile app communicating with your API at some point down the road.
Laravel Blade Views are entirely optional. They're a really nice templating engine, and not necessarily incompatible with React at the same time either. But if you're more comfortable managing your UI in a separate codebase, the short answer is, it all depends, so do what you're comfortable with.

laravel or lumen, which one to choose?

I am a student and I'm making a project, an application which will show data to users on web end and also on android application. but I am confuse which one to choose for backend development, Laravel or Lumen ? My application will have signup function and displayed data from mysql against search queries. There will be 4 to 5 tables and multiple columns in each table. also images to show. So which one I should choose?
From what you have described so far Laravel seems like a perfect fit. Start off with laravel, if you need more speed and a framework focused towards building web services give lumen a try. If you haven't worked with PHP or any other backend app before, go with vanilla PHP.
Goodluck with the app!
If you only need to build an API use Lumen, otherwise Laravel
Well, I recommend Laravel rather than Lumen (Frankly speaking, CI framework may be more suitable, which is simpler and friendly to new user). About 1.5 years ago, I experienced the same dilemma, just like you. For lacking of enough document, I have to migrate my project from Lumen to Laravel when I came across some problems.

Adding REST API to existing PHP website

I'm using some open source code to launch a game. The game is old, around 11yrs. It is a tick based web based game. It's written in php and using MySQL. Basically I want to port this game to ios, instead of using uiwebview I want to build native controls.
I know that it's bad practice to communicate directly with MySQL from an ios app. So what I want to do is add a RESTful API. I'm new to this and have scoured google for answers, does anyone have any pointers of where to start when adding an API to an existing site? It's quite a complex structure.
Thanks.
Paul.
My suggestion is using a framework that is guided towards building an API. I use Slim Framework for my API back end and it's pretty easy to use. If you create a separate URL for this API or include directly into the PHP project as a class it could work.
Some tutorials to get you started are
Say Hello World with Slim
RESTful services with jQuery, PHP and the Slim Framework
Writing a RESTful Web Service with Slim
Hope this helps,
Wes

What are the advantages of ember data and how I can used

I noticed a new feature in ember.js since RC version. I've been reading about it and I know it now can populate data into a model. But what are the advantages and disadvantages of this? My model its populated through JSON but I don't know if it's the best solution.
The other part of my question is: how can I use the ember data for example with zend framework?
I believe you are talking about Ember Data. I used this at a company I worked for a few months ago. At the time it was barely introduced into the main Ember.js repository (we were using it back in the day when it was a second repo called ember-data). It's a pretty nifty feature that allows for simple/rapid CRUD. It's specifically designed to work with Ruby on Rails but with some modifications to your backend you can get it to communicate with Ember Data. From their website:
Without any configuration, Ember Data can load and save records and relationships served via a RESTful JSON API, provided it follows certain conventions.
So its main benefit is rapid development in Ember for communicating with a web service to get and update data. So if your site is getting and saving data just fine you probably don't need to switch. At least wait until it's in a stable release. If you're starting a new app and don't plan on releasing to the public and don't mind having to fix breaking changes (trust me they happen weekly) then Ember Data can be a real help!

Building a REST API quickly from a Database model

I've designed my database diagram(11 entites) for my prototype application. I need to have an REST API on top of this that will allow me to build a prototype android tablet application that talks to it.
Considering this is only for prototype purposes. What would be the quickest way to get a API up and running that would allow me to get, put, delete etc..
Security at this point isn't an issue so even if all add edit delete were open that would be fine.
My initial idea is to build this with PHP and MySQL maybe using the Yii framework to help but I feel there might be something that might be faster for my purpose.
Any thoughts or recommendations or advice?
It is worth looking into API rapid-prototyping tools like Apify (tutorial) since you're starting from scratch. If you're planning to have both an API and a Web site accessing the same data, consider using one framework for both as it helps prevent duplicating logic. CakePHP and Yii are good examples of multipurpose frameworks that are suited for this type of development.
If Python is an option, it is trivial to use a light-weight http framework to build a REST API that accesses a database.
Here's a snippet for a fully functioning http server using the itty framework: https://github.com/toastdriven/itty/blob/master/examples/web_service.py and https://github.com/toastdriven/itty/blob/master/examples/posting_data.py
Look at this project which allows you to create an API REST in seconds.
https://github.com/GeekyTheory/Automatic-API-REST
Features
Creation a powerful API REST of your MySQL Data Base in Seconds.
Management of the API in situ, it is not neccesary an extra data base.
Private tables and fields.
Custom queries.
Installation
Clone the repo.
git clone https://github.com/GeekyTheory/Automatic-API-REST/
Place it in your web folder /var/www/YourWebPage/
Open the file config.php and complete all the fields with the server credencials.
Go to domain.com/AutomaticaApiRest

Categories