Reputation: 1058
I'm switching from Codeigniter to Laravel. In CI its easy to user external libraries or classes, just put it in application/libraries
folder then load it from your controller by:
$this->load->library('libraryName')
Now, I wanna do the same thing in Laravel. I used this scenario :
app
folder called libraries
.Change the composer.json
(which located in the root) as the following:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/libraries" // this was added
]
},
And from CMD run the command composer dump-autoload
.
My class look like this:
class Messages{
function errorMessage(){//....}
function successMessage(){//....}
}
Class stored in file called Messages.php
which located in app\libraries
folder.
I still have the same error:
Class 'Messages' not found
What is the problem and what is the solution?
Upvotes: 1
Views: 3674
Reputation: 341
check your file with autoloading classes /vendor/composer/autoload_classmap.php your class should in there. if it is - check do you actually using composer autoloading on your request?
Upvotes: 0
Reputation: 609
You should see this:
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
));
Add your folder with your class to this array
app_path().'/your-folder-name'
More info can be found here: Where do I put Laravel 4 helper functions that can display flash messages?
Upvotes: 4