Multiple Laravel websites, central codebase - php

I want to create a single Laravel installation that comprises the core functionality of the websites - for example content CRUD functions.
Then on top of this in separate folder on the server for each website have the public folder, css, images etc as well as overriding controllers, models and routes that can be used for specific features per site.
I have achieved the same previously using FuelPHP but have not been able to see where this would be setup in Laravel.
The kind of server folder structure I was anticipating is as below:
/Laravel Core Installation
/app
/vendor
storage
etc
/The first website
public
app (in here would be controllers and models that extend the controllers and models from the Laravel Core Installation folder)
config
etc
/The second website
public
app (in here would be controllers and models that extend the controllers and models from the Laravel Core Installation folder)
config
etc

What you are referring to is called multi tenancy.
Multitenancy refers to a software architecture in which a single instance of a software runs on a server and serves multiple tenants.
http://en.wikipedia.org/wiki/Multitenancy
There are several packages that assist with multi tenancy for Laravel, based on your needs. Some work with seperate database table prefixing, others with completely seperated databases and files.
Some of those packages:
Tenanti
AuraEQ
Hyn *
* Disclaimer; I wrote the last package from this list.

Related

Hierarchy of Yii Framework

Please guide me about the hierarchy of Yii Framework i.e in which directory do we put html, css, javascript files and associate them with each other.
You may check the documentation (http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/)
To answer your question:
backend: the backend application which is mainly used site
administrators to manage the whole system.
frontend: the frontend
application which provides the main interfaces to our target end
users.
console: the console application that consists of the console
commands needed by the system.
common: the directory whose content are
shared among the above applications. As we can see, we divide the
whole system into three applications: backend, frontend and console.
If needed, we can add more applications (e.g. api, to provide Web API
service). We use common to store files that are shared among the
applications.
As you have tagged the question with Yii2 as well, here is the typical directory strucuture of Yii2 Advanced Template:
https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/structure-directories.md
Directories
The root directory contains the following subdirectories:
backend - backend web application.
common - files common to all applications.
console - console application.
environments - environment configs.
frontend - frontend web application.
Root directory contains a set of files.
.gitignore contains a list of directories ignored by git version
system. If you need something never get to your source code
repository, add it there.
composer.json - Composer config described in Configuring Composer.
init - initialization script described in Configuration and
environments.
init.bat - same for Windows.
LICENSE.md - license info. Put your project license there.
Especially when opensourcing.
README.md - basic info about installing template. Consider replacing
it with information about your project and its installation.
requirements.php - Yii requirements checker.
yii - console application bootstrap.
yii.bat - same for Windows.
There are three applications in advanced template: frontend, backend
and console. Frontend is typically what is presented to end user, the
project itself. Backend is admin panel, analytics and such
functionality. Console is typically used for cron jobs and low-level
server management. Also it's used during application deployment and
handles migrations and assets.
There's also a common directory that contains files used by more than
one application. For example, User model.
Frontend and backend are both web applications and both contain the
web directory. That's the webroot you should point your web server to.
Each application has its own namespace and alias corresponding to its
name. Same applies to the common directory.
The css, js for frontend or backend application is generally stored inside the corresponsing web/ folder.
I use follow strukture:
config
environments
runtime
vendor
my-modules
frontend
backend
other vendor
bum
uuu
www-frontend
assets
index.php
www-backend
assets
index.php
www-other-end
assets
index.php
All install/update by composer.In config directory set specific configuration. Can setup unlimeted www.

Laravel two modules in one project

I started to develop a backoffice in laravel (www.example.com/admin) and take use of MVC structure that is offered.
Now it is needed to develop online store in the same domain (www.example.com). What is the best approach to separate the two modules?
For instance one route file/controller folder for backoffice and other for the front site?
Best
Just like api and web routes are split in two separate files in Laravel 5.3, you could split admin and non-admin routes further in two separate files, passing different Controller prefixes (namespaces) to each one and adding an authentication middleware for admin routes. Look into your RouteServerProvider.php.
That's more than enough for a small-to-medium website IMHO.

ZEND Framework folder/file structure

I'm trying to learn zend framework. I managed to install it on my localhost. However i'm having trouble understanding the folder structure? There are 5 main folders after installing the skeleton application - config, data, module, public and vendor.
I've seen some proposed folder structures online, but how to I go about it? Do I just create folders like views, controllers, models etc?
Thanks!
Vendor is where composer installs dependencies and libraries, config is where configuration lives, data is for cache etc, public is where your index.php and css/js/img assets are, you are really interested in module directory that contains application modules. For the start you only really need one module - Application, inside this directory you should have config dir that has module specific config, Module.php - module bootstrap file, view with templates structured per controller and src folder with your code. Inside your src file there is your Application module namespace directory that is placed in Application directory to mimic PSR-4 autoloader namespaces it can contain your application code in this example directory structure: Controller, Form, Model. Model can contain Service, Repository and Entity folders
If you just got started with ZF2 I suggest reading some documentation. Basic things like this can all be found in the documentation. For example here you find more about the folder structure.
I would also suggest taking a look at the ZF2 Skeleton application documentation/tutorial since this will help you understand the basics of a ZF2 application. Here an example on how to structure a new module. Building the album application yourself is a really nice way to get started.

Best practice for Laravel 4 + Zurb Foundation 5?

TL;DR: what is the best way to arrange files, package managers and build tools for Laravel 4 + Zurb Foundation 5 combo (with Compass) as one consistent repository with clean public (static) section?
I wanted to start a fresh project, based on latest Laravel on the backend side and using Foundation for the frontend. I am new to both of these and apparently I missed some of the tooling that was developed meanwhile when I wasn't doing PHP for some time.
My confusion:
Laravel uses Composer for installation and dependency/module management. (Ok, I'm new to Composer)
Foundation is available as a Composer module (but then what?), but generally also as a CLI tool that creates a new project and uses bower for module/dependency management. But then I have two repositories.
Is it required for me to expose all my .scss files, or maybe even put the whole Foundation project into laravel's public dir to make all work?
How do people usually approach using these frameworks together? They shouldn't interfere, but they still have totally different tooling.
Where do I put my foundation files? Keep it as composer module or inside public? How to refer to them? How to have one build everything command?
I have the same issue as using Bootstrap SCSS version for Admin & Foundation SCSS for the frontend. I noticed also that both css frameworks come as composer packages however the issue you have with this approach is that you generally use other Javascript files in a development that will be merged also so using the composer versions just adds to the confusion.
The best solution i found was using either gulp or grunt with bower at the top level of your Laravel build. Rather that go through the configuration for you there is a good article at http://blog.elenakolevska.com/using-grunt-with-laravel-and-bootstrap/ that goes over a bootstrap integration but this can be tweaked for Foundation. This solution is good as grunt has many of the other popular javascript libraries that you may use in your project also..
Alternatively you could use an application like codekit and create a compass project to manage the merging & compiling of your assets into the public folder. As a side note if using git again your would need to exclude additional folders from your project.
If you think of your SCSS framework files as development assets there is no real need for them to be in the project as you only really need one version of Foundation on your development machine.
Your custom SCSS changes can be added to your Laravel project as modules ie a navigation module, via a private composer repo for the project or just added to the Compass project at development time. Your public folder should only be referencing the final merged style.css & java.js files for example. Any images from the framework can then just be copied over to the public folder ie icons etc.. Hope that helps..
Personally I have a "static" directory which houses static files. That is where I use SASS watchers, grunt tasks and basically the entire front-end workflow. The results of that front-end build process gets added to a "production" Laravel public directory after getting built, etc.
A pro of this is that everything (static assets and laravel application) is separate.
A con is that updating Laravel views with any updates in HTML templates you may build in the static directory. If you update the templates, you may also need to update the view files, which becomes more tedious as you add more templating logic around the HTML in the views.
Just one suggestion.

Multiple apps / projects with one Laravel 4 installation

i'm have worked with laravel 3 in the past and used a project structure where multiple apps could use one installation of the framework. now in laravel 4 i am concered if that is still possible. since the bootstrap/autoload.php file requires the vendor/autoload.php file (and so on...), different apps have to use the same autoload files from within the vendor directory, right? i think this would be a big performance problem because the different apps maybe have different requirements, different models to work with and so on. am i thinking right or is there a chance to use one /vendor/ installation for multiple apps without the need to share the autoload files?
to explain my needs: i would like to run different apps (every app with another domain & home directory) which share one database and some models. but the requirements of every app will be very different.
is there any solution? i tried this since the release but found no practicable way.
Have you tried http://laravel.com/docs/routing#sub-domain-routing?
You could create a route group and assign a filter function to that route group to do specific autoloads?
How about modifying bootstrap/autoload.php and vendor/autoload.php to load autoload stuff per project to some kind of sub-directory structure under vendor/composer/.
Not sure, how to change composer to generate that kind of project specific autoload directories. Maybe it needs changing composer?

Categories