How to add a library folder to Laravel 4

Author :Andrew     Category : PHP, Programming     22 Feb | 2 Comments

I typically use a library folder in my projects to group of files that you want to use in different projects but don’t want to use Satis to manage the contained files. This folder could also be a helper folder for functions that are static and are mainly generic helpers but don’t quite fit in a model. So in this example I’ll be adding a library folder and have it autoloaded by Laravel. The process for a helpers folder is the same, just replace library with helpers.

First step is to create the folder. (I assume you’re already in laravel project.)

cd app/

mkdir library

cd library

Now we need to add the folder to the autoload file. We will return to laravel project root and view the composer file.

cd ..

vim composer.json

Should look something like.

{
 "require": {
 "laravel/framework": "4.0.*"
 },
 "autoload": {
 "classmap": [
 "app/commands",
 "app/controllers",
 "app/models",
 "app/database/migrations",
 "app/tests/TestCase.php"
 ]
 },
 "minimum-stability": "dev"
 }

We’re going to add the library directory.

{
 "require": {
 "laravel/framework": "4.0.*"
 },
 "autoload": {
 "classmap": [
 "app/commands",
 "app/controllers",
 "app/library", /* Added here */
 "app/models",
 "app/database/migrations",
 "app/tests/TestCase.php"
 ]
 },
 "minimum-stability": "dev"
 }

Let’s reload the autoload. (Assuming composer is an alias.)

composer dump-autoload

Now you can use the library folder.

Tags: , , ,
2 comments

Latest News

8 Jul

How to format hdfs in AWS Elastic Map Reduce

It’s insanely simple. Connect to your master node within AWS Elastic Map Reduce. Then you’ll want to connect to the hadoop cluster and reset the NameNode file handlers. That’s it. That’s how ...

14 May

How to use load data from s3 in to elastic map reduce

How to load data from s3 in to Amazon Elastic Map Reduce is fairly easy. The trick is to use s3n or s3 at the data ...

 

I’m a Engineering Manager currently working at NinjaMetrics where I lead a team developing predictive anayltics using various technologies including AWS, Debian, PHP, Java, Hadoop, MySQL, and many more. I’m heavily involved in all aspects of ...