You can create a new directory somewhere in the application directory, for example app/libraries
Then, in your composer.json file, you can include app/libraries in your startup class map:
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "laravel/framework": "4.2.*", }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/libraries", <------------------ YOUR CUSTOM DIRECTORY "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ] }, "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] }, "config": { "preferred-install": "dist" }, "minimum-stability": "stable", }
Be sure to run composer dump-autoload after modifying your composer.json.
Suppose your class name is called CustomClass.php and is located in the app/libraries directory (so the full path is app/libraries/CustomClass.php ). If you correctly placed your class on your class, your convention will most likely be called libraries . For clarity, we will call our custom namespace to avoid directory confusion.
$class = new \custom\CustomClass();
Alternatively, you can give it an alias in the app/config/app.php :
'aliases' => array( ... 'CustomClass' => 'custom\CustomClass', ... )
And you can create an instance of the class from anywhere in your application, as with any other class:
$class = new CustomClass();
Hope this helps!