We can easily auto-load libraries in Laravel 4.x by using namespaces in our application. Then put all libraries you code under that namespace.
Suppose our directory structure would then be:
libraries
Myapp
Search (note directory is capitalized)
Search.php
SearchFacade.php
SearchServiceProvider.php
AnotherLib
Then your classes will follow that namespace:
File: Myapp/Search/Search.php
<?php namespace Myapp\Search;
class Search { ... }
And finally, your autoloading setup:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/libraries",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
,
"psr-0": {
"Myapp": "app/libraries"
}
},
By this way we can autoload 'libraries' in Laravel 4.x.
0 Comment(s)