I'm new to Laravel.
I'm working on a project which involves a public facing website and back-office application. Both are web applications and suppose to be hosted on different domains.
Website - the Public facing website using the database to pull data.
Back-Office - Backoffice or Admin app to create/update/delete stuff again using the same database should have it's own RBAC.
The reason for keeping these two apps separately is so that on the public facing website we don't push unnecessary code and keep it lean and clean. However, both of them are using the same database so I want to create a module/app/plugin (Not sure how to name it in Laravel) which can be shared among both applications for database models or any other business logic which can be shared between both apps.
Any idea how to achieve that with laravel framework?
Based on my experience, the most obvious approach would be to have one backend (API) used by the two frontends.
API : Exposing REST endpoints, configured with proper authorizations (some endpoints would only be for admins users).
Website : A classic website (SPA or not) interacting with the business logic through the API.
Back-Office : Same story as the website.
It's somehow a microservice architecture. There is a lot of pros and cons for it, but considering you don't want to push unnecessary code, spreading into different apps seems like appropriate.
If you want to keep one code base, I would consider having a load balancer (like HaProxy or Nginx) in front of your Laravel app to handle requests from configured domains to appropriate routes. For example :
acme.com root would be / for Laravel
bo.acme.com root would be /admin for Laravel
Related
My main application is being built with Vue (mydomain.com), I also have a REST API (api.mydomain.com) and then my assets (assets.mydomain.com).
The API is unlikely to be used by other developers, and is only for my convenience when building the spa with Vue. Considering this: would it be better to build a single Laravel application that handles all three subdomains OR have a Laravel application that handles the API, a standalone Vue build for my main application and then serve the assets as a seperate build entirely?
What are the pros/cons for a single build vs three?
I haven't used Laravel in that context but I sure prefer the more modularized approach of having different builds for different functionality.
I normally use the approach with Node.js where I have both assets and api handled by the backend. (Express app etc) and then separate build fetching the data to render in the spa using React.
This build benefits scalability since you can easilly maintain, track and debug the code. Obviously it makes it also easier for unit testing. And the performance of the SPA isn't affected by the payload routing in the backend since it runs separately and only interact upon request (REST API in my case).
I hope I provided useful insight.
I am working in a project which will have a web, android and iOS application.I have decided using laravel 5.4 to create the web application and also there will the rest api to feed all these app. The api should also be secured so that only my app can access them.
Anyone please tell me from your previous experience what will be the correct way and the best practice to do this
You can use Node.js or Python on which you can develop rest API very easily.The framework like express in Node.js and Flask in python will let you get started with your API within 30 min.After that, you can deploy the API to Heroku to get secure access
If the web, android and IOS application relate to the same project / resources (e.g. database tables, etc.), the easiest way to do this would be a single Laravel project.
In your routes directory, you can have 3 different files (say web.php, ios.php and android.php) to define the routes. Similarly, you can place controllers in separate directories while keeping the Eloquent models/migrations, etc. the same for all three.
To use different authentication methods for all three, you can add custom guards in Laravel.
I would not build anything in larvel and run away form php as soon as possible. Go learn node.js or django. Death to php.
The best current framework to builds apis is Sanic.
Sanic 33,342 Requests/sec 2.96ms Avg Latency
https://github.com/channelcat/sanic
I also like python flask because it is very simple to understand and get something up and running quickly.
Your app currently does not need to be super optimal all you need to is getting working, But best practice wise i think the most important thing for building apis for mobile apps is backwards compatibility.
Sometimes your going to want to update the your app.
Users often don't update the apps. So if you build a new api all the people who dont update their app will get error messages. So just make sure you make a new route with the version name in the prefix in the app. There is alot of other things you can do like rate limiting,Salting your apis and ect. If you dont have that many users don't worry about this yet. Just build it and then latter learn when you need to learn in.
We are planning to develop a web application for job applications. In the first two years we expect the traffic to be about 3'000 - 6'000 visitors per day. At a later stage the traffic will grow up to 10'000 - 20'000 visitors per day.
Is there an advantage in separating frontend and backend (frontend standalone vue.js which calls the REST-API of Laravel) in compare to a all-in-one Laravel application which includes Vue inside the blade templates?
Thank you
If you plan on delivering your product in the form of:
a REST API,
and a frontend application
Then you should definitely come up with two different repositories/project.
Starting with an "all-in-one" application for both backend REST API and frontend application looks simpler, as Laravel comes with Vue.js out of the box. But even if it's helpful regarding frontend, it is focusing on backend, PHP, and Laravel. I bet on your developers mixing backend and frontend pretty soon :)
Consider bootstrapping your frontend application with vue-cli as a standalone project, to get huge benefits from its webpack configuration, and a top-notch (frontend) developer experience. Your frontend application will be better from day one, focusing on its prerequisites: delivering high quality user experience.
laravel is a very performant framework and if you use caching techniques with a good backend architecture it will support the load without issues.
That being said, a client/API will de facto be more performant, since the only thing that will occup the bandwith will be json object instead of full pages, and for the client side you rely upon the client hardware.
Another big win for a client/API approach is for when you will want to develop Ur Mobile/Desktop apps. The API will be ready and you'll be focus on just the new clients u'll have to develop. If u were on a server serving pages and a lot done within the controller/actions returning those computed pages, you will have to extract the API from those controllers and makes those calls the API instead.
I'm building a series of web applications to use in a small business. We will be using laravel framework to build these applications. The first app will manage users, authentication and authorization for all future applications.
I have 2 doubts:
Is there some best pratice / model for this auth integration? How can I tell app B that the user is authenticated and has access to it? I want to build different laravel apps in order to make it easier to maintain, but (at least for now) they'll run in the same server.
Is it possible to make this integration with another php, non-laravel app? I have one legacy webapp, I'm trying to write the session data that authenticates it inside my laravel code and redirecting the user to the app, but the session data apparently isn't "persisting".
Thanks in advance.
It sounds like you are building a micro service architecture if you follow this methodology there is no reason your apps or services even have to be written in the same language as long as they and all interact using RESTful services.
More reading:
http://martinfowler.com/articles/microservices.html
I'm building an SaaS application in Laravel-5. Basically, I want our client to be able to point their domain to our name servers and effectively the application will load their website template (which will vary from client to client). It will also allow our clients' members to login to their account through their website and load all of their personal details.
Is this possible in Laravel-5 and can anyone point me in the right direction?
There are several ways to support multi tenancy in laravel.
Using middleware you can dynamically mutate the request object to modify behavior of the application.
By modifying the path locations you can then change where views and almost anything else is loaded from.
Landlord, a single database multi-tenancy package for Laravel & Lumen 5.2+.
Another proven package is Tenanti which handles custom database connections and even observes models to track changes to different database connections.
I'm currently maintaining a multi tenancy package for Laravel that allows complete division of responsibility for databases, files etc while maintaining a system connection for system wide settings and hostname setup.
Deprecated:
If you only want to have one database that stores all tenants, you might be interested in AuraEQ, I'm not sure there should be others. Is now Landlord.