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

23 Nov

Mozilla Developer Edition

I recently discovered Mozilla Developer Edition. So far I’ve love it’s inline ability to edit css. It’s an entirely natural way to tweak the css on the ...

7 Oct

October CMS How to replace component templates from plugins

How can you replace component templates from plugins? IE I want to replace the posts default template in the blog plugin with my own markup. Post List from the blog plugin – ...

 

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 ...