View and controllers on different machines in Laravel - php

I have got a requirement from a customer that my web UI should not have any direct access to my database. My web app is built in php using the Laravel framework and Eloquent. One option is rewriting the code in my controller and model into a webservice (in any other language be it php or java) and calling the webservice from the UI, but this will involve tremendous work. Is there any way in Laravel where I can move my controller and model to another server and calling the controller from UI via Laravel routes? The view must be on one machine and the model-controller on another machine.

To the best of my knowledge this cannot work. Although Laravel is highly customisable, the work involved in moving your entire application to a new server while keeping the view where they are is extremely too much and possibly won't work.
Your suggestion to use web services is something to consider but in reality you will be creating a static website in one server which uses API's to talk to Laravel on a other servers. They will not be views and definitely not in blade templates. Remember that you have other UI related dependencies in vendor and public directories.
My suggestion is to have the DB on a separate server which you can connect to by editing the config files - this is a very normal setup.
Then if you want you can create some web pages which use the API to talk to Laravel from another server but again I cannot see why this would be needed as the views are still not accessible by anyone other than the server.
Please let me know if I'm missing something :)

Related

Yii2 Rest API Location

I needed to know which folder is more suitable to host my Rest API in Yii2 template advanced, backend or frontend.
I also saw some examples where developers created a new directory, called it "api" and programmed the API from there, but I don't find much information by developing from this method.
If you know the most correct way to do it, I would apreciate if you could explain me.
That totally depends on your requirements if it is going to be a complete full app or just a single controller with a few actions or a single ActiveController.
But a good way is to keep things separate just like you are using the advance-app and you have the backend and frontend folders so that you can differentiate the code base, and keep the code in their concerned folders, those folders are actually 2 separate applications running separately with their own separate configurations i.e backend/config/* and frontend/config/*, and can share some common configurations like database and others from the common/config/*. Same like that you can create a separate application/folder where you can have all the code base and configurations related to api you are going to build.
You can find a very good reference for adding more apps into your existing application by Yii here on GITHUB which will clear your concept about how to add more apps.
Then you can go to this article by Budi Irawan's Tech Blog which uses the advance-app to add a new application for the API. You will find the directory structure with example models and controllers along with testing them with POSTMAN.
Backend and frontend are also just a folder in the Yii2 advance app with just namespace different, they are different for our understanding, it is not necessary that you use backend for backend purpose only.
So for the API, you can use any of these folders, but it is always recommended to put thing separately like we put backend thing in backend folder and frontend things in frontend folder.
It's totally up to you and your coding style.
i prefer putting Rest API into a separate module, for instance into "common\modules\api". that way i can "mount" the api in backend or frontend via configuration. Also, nice urls are automatically provided, like /api/<controller>/<action> (where api is the name of your module).
One more thing to consider is how to update your api. in case of modules everything is well organized. you could start with "v1" and put your controllers in here, and move up to "v2" with a different set of controllers. so your first api endpoint would read /v1/users, later on you can additionally provide /v2/users.
more about modules here
read "URL Rules" here

SAPUI5 For the UI and LARAVEL for backoffice

I have to begin a new project and that's 2 years ago that I'm working on SAPUI5, But for severals reasons I have to use the Laravel 5.1 Framework to handle the database logic and controller to get and put data from and to the database.
I appreciate the power of SAPUI5 and I would like to use it for the front-end of my app.
My question is : It is possible to handle a server application with those two technologies?
My second question is : Which hosting I have to choose, because that my client want a kind of desktop app, and for this I thought to use node webkit package. And for that i have to launch a node server. In my goDaddy shared hosting i don't have this possibility.
Thank you for your help!
You can definitely combine Laravel as back-end technology with SAPUI5/OpenUI5 as front-end technology. As Laravel provides the front-end with restful services, you're probably best-off leveraging the JSONModel in your UI5 application.
Laravel is a PHP framework, so you'll need to look for a PHP host. If a host is capable of running PHP, it is also able to serve the static UI5 content.
If you want to package your app as a desktop application, NW.js will work, but Electron will do the job too. A very nice comparison between the two frameworks can be found here: http://tangiblejs.com/posts/nw-js-electron-compared.
Please do note that both frameworks turn your application into a desktop application and will run on the desktop. You won't need to find a server that runs node.js. You do need a server that runs PHP for your back-end Laravel logic.

Laravel 4 with Ember App

I am creating a web application. I am fairly accustomed to Laravel and how it functions. I would like to know how I incorporate Ember into the Laravel setup. I am guessing public folder, but when I use Yeoman to install Ember into the public it involves the node_modules and gruntfile. My question is should all this be in the public folder (any security concerns?)
Some people say it is not good to mix the two. I would like multiple single page views so it makes sense. Plus it is a good challenge to get stuck into. I have researched any answers and had no luck.
You need to put your script files in your public folder, otherwise the clients browser wouldn't be able to fetch and use them. No security concerns there. That includes grunt, bower or any other files (if it happens that you need them in your production server).
We at work use Laravel and Ember. Ember is our true front end and Laravel is our true back end. It is a very good idea to use them together. It's also a good idea to start with multiple apps so you don't get overwhelmed in no time. In time, you can evolve to one huge app and/or you'll start writing components and mixins you can reuse across your apps.
Just a note: I use a combination of bootstrapped data (json_encoded in .blade views) and data fetched from the server via getJSON (I don't currently use Ember Data because is not production ready yet)
I hope this helps you!

Where can I find detailed resource about application structure with Laravel 4 and AngularJS?

I recently started to develop a social network, but the problem is i started to mix my Laravel view with AngularJS what led me to a few problems.
I was searching around the net but was not able to find any info about this.
Could someone help me out with this or give me a hint?
I prefer to decouple my Angular.js application from the backend (any backend). You can pick a tool like Linemanjs or Yeoman.
With Lineman (which is the one I use) you develop your app without any backend, in an "isolated way". You can use a fake backend while you are in development mode or even you can have laravel running at port 4567 (just an example) and tell lineman that there is a real backend at 4567 to create a proxy (so you can use your real backend even when your app is in a different folder).
The advantages are many. Decoupled from any backend, so you can switch it to others without any change in Angular. You can take advantage of a pre-configure set of tasks for grunt like Coffeescript, lint, sourcemaps, auto creation of $templateCache, ngmin to avoid minification problems, minification, concatenation... And more if you want.
You also have unit and e2e tests preconfigured...
In short, using this workflow you can create an Angular.js app which plays with any backend and provides you with a lot of tools to create your app easily.
To deploy, both lineman and yeoman creates a "dist" folder with your app itself, just a bunch of static files.
To deploy it with laravel, you just need to drop everything (except the index.html) to the /public folder of laravel. Then convert the index.html to something like home.php in the laravel's /view folder and create a route for it.
We only need to be able to serve the index.html with laravel and that is the best way I found. With that we are able to use html5 mode and make everything work perfect and both part decoupled.
Cheers.

Confusion- Should I use CodeIgniter or something else for below case

As I have never develop any web-app from scrach. I want to know that:
Background:
I have to develop web-app whose database will be on some other machine[say server], and every communication with database has to be done using SOAP web service[database is on server]. I'm looking forward to use CodeIgniter framework to achieve this.
As CodeIgniter is MVC based, it has divided into
Module - can say storage
View - can say output
Controller - can say communicator between view and module
Confusion: Can I use Condigniter for app whose database is remote.
As I have seen tutorials and examples, all are of based on local database.
So can someone guide me, Is it possible to have all communication with database in same framework.
As much I have followed tutorials, flow is like(for local database)
Request: view -> controller -> module
Response: module -> controller -> view
so please tell me,how this will be in the CodeIgniter framework? Is it possible? What can be done? I'm confused,how to run app without the local database/how can I communicate with SOAP services using model class. or what to do? Or should I move to core php,if its not possible in CodeIgniter framework?? Please help me out. Thanks a lot!
IMP Update:**
Communication with database has to be done by only web service(SOAP)
Typically, a CodeIgniter app has the following setting in your database configuration file:
$db['default']['hostname'] = "localhost";
Instead of localhost, you should use whatever you have set up to connect to your external database.
Have a look at:
http://ellislab.com/codeigniter/user-guide/database/configuration.html
Note: You should not be asking if this is possible or not with CI. CI is a framework for building applications and it should be able to do what you want, don't think about what it can or can't do, think if it's the right tool for the job from an architectural standpoint.

Categories